From: Lucas Bajolet Date: Wed, 18 Jun 2014 19:38:06 +0000 (-0400) Subject: benchmarks: Reunited common functions for benches in a new shell file. X-Git-Tag: v0.6.6~22^2 X-Git-Url: http://nitlanguage.org benchmarks: Reunited common functions for benches in a new shell file. Signed-off-by: Lucas Bajolet --- diff --git a/benchmarks/bench_common.sh b/benchmarks/bench_common.sh new file mode 100644 index 0000000..c600732 --- /dev/null +++ b/benchmarks/bench_common.sh @@ -0,0 +1,87 @@ +#!/bin/bash +# This file is part of NIT ( http://www.nitlanguage.org ). +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Common functions for all the bench scripts + +# Run a single command multiple time and store the execution times +# in the current $res file. +# +# $1: title of the command +# $2: long desription of the command +# rest: the command to execute +function bench_command() +{ + if [ "$dry_run" = "true" ]; then return; fi + local title="$1" + local desc="$2" + shift + shift + if test "$verbose" = true; then outputopts="/dev/stdout"; else outputopts="/dev/null"; fi + timeout="time.out" + echo "$title" > "$timeout" + echo "# $desc" >> "$timeout" + echo "\$ $@" >> "$timeout" + echo + echo "** [$title] $desc **" + echo " $ $@" + + # Execute the commands $count times + for i in `seq 1 "$count"`; do + /usr/bin/time -f "%U" -o "$timeout" -a "$@" > $outputopts 2>&1 || die "$1: failed" + echo -n "$i. " + tail -n 1 "$timeout" + done + + line=`compute_stats "$timeout"` + echo "$line ($res)" + echo $line >> "$res" +} + +# Run a simble command witout storing the execution time +# Used to display command on verbose and skip long executions when dry_run is given +# $@ command to execute +function run_command() +{ + if [ "$dry_run" = "true" ]; then return; fi + echo " $ $@" + "$@" || die "$@: failed" +} + +# Check if the test should be skiped according to its name +# $1: name of the test +# $2: description of the test +# $NOTSKIPED: arguments +function skip_test() +{ + if test -z "$NOTSKIPED"; then + echo "* $1" + return 0 + fi + if test "$NOTSKIPED" = "all"; then + : # Execute anyway + elif echo "$1" | egrep "$NOTSKIPED" >/dev/null 2>&1; then + : # Found one to execute + else + return 0 + fi + if test -n "$html"; then + echo >>"$html" "

$1

" + fi + echo "*" + echo "* $1 *****" + echo "*" + return 1 +} + diff --git a/benchmarks/bench_engines.sh b/benchmarks/bench_engines.sh index 55db63e..abc65e3 100755 --- a/benchmarks/bench_engines.sh +++ b/benchmarks/bench_engines.sh @@ -17,6 +17,7 @@ # TODO: cleanup and libify the helper-parts +source ./bench_common.sh source ./bench_plot.sh ## CONFIGURATION OPTIONS ## @@ -35,76 +36,6 @@ function die() died=1 } -# Run a single command multiple time and store the execution times -# in the current $res file. -# -# $1: title of the command -# $2: long desription of the command -# rest: the command to execute -function bench_command() -{ - if [ "$dry_run" = "true" ]; then return; fi - local title="$1" - local desc="$2" - shift - shift - if test "$verbose" = true; then outputopts="/dev/stdout"; else outputopts="/dev/null"; fi - timeout="time.out" - echo "$title" > "$timeout" - echo "# $desc" >> "$timeout" - echo "\$ $@" >> "$timeout" - echo - echo "** [$title] $desc **" - echo " $ $@" - - # Execute the commands $count times - for i in `seq 1 "$count"`; do - /usr/bin/time -f "%U" -o "$timeout" -a "$@" > $outputopts 2>&1 || die "$1: failed" - echo -n "$i. " - tail -n 1 "$timeout" - done - - line=`compute_stats "$timeout"` - echo "$line ($res)" - echo $line >> "$res" -} - -# Run a simble command witout storing the execution time -# Used to display command on verbose and skip long executions when dry_run is given -# $@ command to execute -function run_command() -{ - if [ "$dry_run" = "true" ]; then return; fi - echo " $ $@" - "$@" || die "$@: failed" -} - -# Check if the test should be skiped according to its name -# $1: name of the test -# $2: description of the test -# $NOTSKIPED: arguments -function skip_test() -{ - if test -z "$NOTSKIPED"; then - echo "* $1" - return 0 - fi - if test "$NOTSKIPED" = "all"; then - : # Execute anyway - elif echo "$1" | egrep "$NOTSKIPED" >/dev/null 2>&1; then - : # Found one to execute - else - return 0 - fi - if test -n "$html"; then - echo >>"$html" "

$1

" - fi - echo "*" - echo "* $1 *****" - echo "*" - return 1 -} - # HELPER FOR NIT # # Run standards benchs on a compiler command diff --git a/benchmarks/bench_languages.sh b/benchmarks/bench_languages.sh index d9db525..fea39ff 100755 --- a/benchmarks/bench_languages.sh +++ b/benchmarks/bench_languages.sh @@ -17,6 +17,7 @@ # TODO: cleanup and libify the helper-parts +source ./bench_common.sh source ./bench_plot.sh ## CONFIGURATION OPTIONS ## @@ -33,74 +34,6 @@ function die() died=1 } -# Run a single command multiple time and store the execution times -# in the current $res file. -# -# $1: title of the command -# $2: long desription of the command -# rest: the command to execute -function bench_command() -{ - if [ "$dry_run" = "true" ]; then return; fi - local title="$1" - local desc="$2" - shift - shift - if test "$verbose" = true; then outputopts="/dev/stdout"; else outputopts="/dev/null"; fi - timeout="time.out" - echo "$title" > "$timeout" - echo "# $desc" >> "$timeout" - echo "\$ $@" >> "$timeout" - echo - echo "** [$title] $desc **" - echo " $ $@" - - # Execute the commands $count times - for i in `seq 1 "$count"`; do - (ulimit -t 300; /usr/bin/time -f "%U" -o "$timeout" -a "$@") > $outputopts 2>&1 || die "$1: failed" - echo -n "$i. " - tail -n 1 "$timeout" - done - - line=`compute_stats "$timeout"` - echo "$line ($res)" - echo $line >> "$res" - rm $timeout -} - -# Run a simple command witout storing the execution time -# Used to display command on verbose and skip long executions when dry_run is given -# $@ command to execute -function run_command() -{ - if [ "$dry_run" = "true" ]; then return; fi - echo " $ $@" - (ulimit -t 180; "$@") || die "$@: failed" -} - -# Check if the test should be skiped according to its name -# $1: name of the test -# $2: description of the test -# $NOTSKIPED: arguments -function skip_test() -{ - if test -z "$NOTSKIPED"; then - echo "* $1" - return 0 - fi - if test "$NOTSKIPED" = "all"; then - : # Execute anyway - elif echo "$1" | egrep "$NOTSKIPED" >/dev/null 2>&1; then - : # Found one to execute - else - return 0 - fi - echo "*" - echo "* $1 *****" - echo "*" - return 1 -} - ## HANDLE OPTIONS ## function usage()