diff options
author | dgp <dgp@users.sourceforge.net> | 2016-04-19 20:35:49 (GMT) |
---|---|---|
committer | dgp <dgp@users.sourceforge.net> | 2016-04-19 20:35:49 (GMT) |
commit | 66032e8a327e0498b0d8970307452f66c69be25c (patch) | |
tree | 345b92b9d0c1be0f8ff45032a38884929744545e /tests/langbench | |
parent | 0a228666ae8b3189ae92ff7624263de1455c24ff (diff) | |
download | tcl-66032e8a327e0498b0d8970307452f66c69be25c.zip tcl-66032e8a327e0498b0d8970307452f66c69be25c.tar.gz tcl-66032e8a327e0498b0d8970307452f66c69be25c.tar.bz2 |
Fork of Tcl used in the "Little" project.
http://www.mcvoy.com/lm/little/index.html
Diffstat (limited to 'tests/langbench')
49 files changed, 846 insertions, 0 deletions
diff --git a/tests/langbench/BEFORE-PERF b/tests/langbench/BEFORE-PERF new file mode 100644 index 0000000..831ee2a --- /dev/null +++ b/tests/langbench/BEFORE-PERF @@ -0,0 +1,26 @@ +These are the langbench results from the source base as of early Nov-2007. + +lang cat grep hash loop proc fib sort wc +tcl 2.10 4.10 1.51 0.06 1.27 3.76 5.40 0.97 +l 2.10 4.21 1.48 0.08 0.51 3.92 5.76 coredump :( + +vs now, late Jan-2008 + +lang cat grep hash loop proc fib sort wc +tcl 0.81 0.97 1.13 0.05 0.98 3.45 2.85 1.21 +l 0.82 0.97 1.14 0.05 0.45 3.36 3.11 1.93 + +Factor better: +lang cat grep hash loop proc fib sort wc +tcl 2.6x 4.2x 1.3x wash 1.3x wash 1.9x .8x (whoops) +l 2.6x 4.2x 1.3x wash wash 1.2x 1.9x NA + +And other languages for comparison: +lang cat grep hash loop proc fib sort wc +pl 0.36 0.36 0.61 0.07 0.40 3.68 2.15 1.00 +py 0.46 1.50 0.48 0.15 0.23 1.27 2.26 0.49 +rb 0.82 0.73 1.64 0.29 1.13 4.06 4.29 3.09 + +Amount slower than perl: +lang cat grep hash loop proc fib sort wc +tcl/l 2.3x 2.7x 1.9x faster wash faster 1.4x 1.2x diff --git a/tests/langbench/BEFORE.pcre b/tests/langbench/BEFORE.pcre new file mode 100644 index 0000000..e62a0d5 --- /dev/null +++ b/tests/langbench/BEFORE.pcre @@ -0,0 +1,8 @@ +langbench version 0.6 results: +lang cat grep hash loop proc fib sort wc +tcl 0.54 2.61 0.87 0.05 0.91 2.27 2.38 0.80 +tcl 0.53 2.59 0.87 0.05 0.92 2.28 2.36 0.79 +tcl 0.55 2.58 0.87 0.05 0.89 2.32 2.37 0.79 +l 0.56 1.88 0.84 0.04 0.30 2.14 2.64 1.33 +l 0.55 1.87 0.86 0.05 0.30 2.14 2.63 1.30 +l 0.55 1.89 0.85 0.04 0.32 2.15 2.64 1.32 diff --git a/tests/langbench/ChangeLog b/tests/langbench/ChangeLog new file mode 100644 index 0000000..d8c6cec --- /dev/null +++ b/tests/langbench/ChangeLog @@ -0,0 +1,10 @@ +0.6 + - Make the grep expr be [^A-Za-z]fopen\(.*\) since that is not + trivially optimized. + - Add fibonacci benchmark. + - Make the procedure calls take more arguments. + - add a findtclsh so that if you run this in a tcl source tree + under tests/langbench it just works. + - Allow setting of each language with RUBY=/build/ruby/ruby + (for testing new versions like the ruby with a byte code + compiler). diff --git a/tests/langbench/PERF_LOG b/tests/langbench/PERF_LOG new file mode 100644 index 0000000..2e8ce52 --- /dev/null +++ b/tests/langbench/PERF_LOG @@ -0,0 +1,20 @@ +2.6ghz T61 + +2008-02-02 + +lang cat grep hash loop proc fib sort wc +pl 0.35 0.34 0.62 0.07 0.40 3.65 2.19 1.00 +py 0.45 1.48 0.49 0.15 0.22 1.21 2.15 0.49 +rb 0.82 0.73 1.57 0.28 1.12 3.94 4.28 3.10 +tcl 0.78 0.93 1.11 0.05 0.99 3.54 2.84 1.16 +l 0.79 0.93 1.13 0.05 0.46 3.42 2.98 1.86 + +2008-04-10 + +lang cat grep hash loop proc fib sort wc +pl 0.38 0.36 0.64 0.07 0.42 3.90 2.27 1.04 +py 0.48 1.55 0.51 0.16 0.23 1.26 2.24 0.51 +rb 0.87 0.76 1.63 0.29 1.18 4.17 4.53 3.23 +tcl 0.84 1.05 1.19 0.06 1.06 3.75 2.91 1.23 +l 0.84 1.02 1.22 0.05 0.46 3.66 2.90 1.85 + diff --git a/tests/langbench/README b/tests/langbench/README new file mode 100644 index 0000000..f8007ba --- /dev/null +++ b/tests/langbench/README @@ -0,0 +1,56 @@ +langbench is a simplistic set of microbenchmarks designed to see how +well a scripting language performs at basic operations. The intent is to +have a set of tests that encourage each language team to optimize their +language in a way that would benefit the widest possible set of users. +The version number of this test suite will be 1.0 when there is widespread +agreement that these are the "right" set of benchmarks, much like lmbench +was the "right" set of benchmarks for operating systems. + +We (BitKeeper Inc) are using it to benchmark our scripting language, you can +use it for whatever you like. + +You may use for langbench any purpose provided that if you use the +"langbench" name you report all results for all languages like so: + +langbench version 0.5 results: +lang cat grep hash loop proc sort split +pl 0.85 0.85 1.38 0.24 0.68 4.72 5.13 +py 0.81 2.97 1.03 0.34 0.40 4.37 1.56 +rb 1.81 1.68 4.18 0.53 1.04 8.00 3.66 +tcl 2.02 1.45 2.44 0.13 0.72 7.48 3.93 +l 2.02 1.48 2.43 0.12 0.73 8.11 3.94 + +langbench version 0.6 results (faster cpu accounts for some diffs): +lang cat grep hash loop proc fib sort wc +pl 0.37 0.34 0.62 0.11 0.38 4.35 2.02 1.03 +py 0.38 1.99 0.46 0.18 0.21 1.08 1.83 0.48 +rb 0.84 0.81 1.98 0.31 0.59 2.95 3.33 2.33 +tcl 0.75 2.64 1.09 0.07 0.89 2.65 3.46 0.90 +l 0.71 2.03 1.14 0.07 0.29 2.49 3.88 1.54 + +with the exception that you may leave off the L language until it is +widely distributed (defined as apt-get install l just works or is +included with the tcl package). + +Note that for the cat, grep, hash, loop, proc, sort benchmarks the number +printed is the microseconds for the implied operation, i.e., for cat, +it is usecs/line, for sort it is the usecs/line to sort and print each +line, etc. + +Test descriptions: + cat copy stdin to stdout + grep match a regular expression against stdin, print each match + hash use each line of stdin as a hash key, value is 1. + loop measure the cost of a loop + proc measure procedure call cost + sort sorts stdin to stdout + split [Not used because the semantics are different across langs] + +Input data is a million lines of code generated like this: + + for i in 1 2 3 4 5 6 7 8 9 0 + do cat tcl/generic/*.[ch] + done | head -1000000 > DATA + +This file and tests are at http://www.bitkeeper.com/lm/langbench.shar + diff --git a/tests/langbench/RUN b/tests/langbench/RUN new file mode 100644 index 0000000..bbb8eaf --- /dev/null +++ b/tests/langbench/RUN @@ -0,0 +1,58 @@ +test X$LANGBENCH = X && { + LANGBENCH=. + test -d langbench && LANGBENCH=langbench +} +test X$TCLSH = X && { + test -x gui/bin/tclsh && TCLSH=gui/bin/tclsh + test -x ../gui/bin/tclsh && TCLSH=../gui/bin/tclsh +} +test X$TCLSH = X && { + echo Please set TCLSH + exit 1 +} +test X$PERL = X && PERL=perl +test X$PYTHON = X && PYTHON=python +test X$RUBY = X && RUBY=ruby +test "X$LANGS" = X && LANGS="pl py rb tcl l" +test "X$TESTS" = X && TESTS="cat grep hash loop proc fib sort wc" +export TCL_REGEXP_PCRE=1 +echo "langbench version 0.6 results:" +echo -n "lang " +for i in $TESTS +do echo -n "$i " +done +echo "" +for lang in $LANGS +do + case $lang in + pl) CMD=$PERL;; + py) CMD=$PYTHON;; + rb) CMD=$RUBY;; + tcl|l) CMD=$TCLSH;; + esac + N=1 + test X$RUNS = X || N=$RUNS + while (($N > 0)) + do + printf "%-8s" $lang + for test in $TESTS + do + DATA=DATA + test $test = wc && DATA=SMALL + export LANG_TEST=$test + for run in 1 2 3 + do time $CMD $LANGBENCH/${test}.${lang} $DATA > /dev/null + done 2>&1 | + perl -e '$min = 1000000; + while (<>) { + if (/real.*0m(.*)s/) { + $min = $1 if $1 < $min; + } + } + printf "%-8.2f", $min;' + done + printf "\n" + N=`expr $N - 1` + done +done +exit 0 diff --git a/tests/langbench/WEIRD b/tests/langbench/WEIRD new file mode 100644 index 0000000..b6a2533 --- /dev/null +++ b/tests/langbench/WEIRD @@ -0,0 +1,9 @@ +If the regexp is ^$ then the python code gets one more match than the others. + +python's split gets the word count wrong: + + wc -w: 3647213 + perl: 3647213 + ruby: 3647213 + tcl: 3647213 + python: 3647250 diff --git a/tests/langbench/cat.l b/tests/langbench/cat.l new file mode 100644 index 0000000..ca6ca1c --- /dev/null +++ b/tests/langbench/cat.l @@ -0,0 +1,18 @@ +void +main(int ac, string av[]) +{ + string buf; + FILE f; + int i; + + fconfigure("stdout", buffering:"full", translation:"binary"); + for (i = 1; i < ac; ++i) { + unless (f = open(av[i], "rb")) continue; + while (gets(f, &buf) >= 0) { + // roughly 40% slower than puts + // printf("%s\n", buf); + puts(buf); + } + close(f); + } +} diff --git a/tests/langbench/cat.pl b/tests/langbench/cat.pl new file mode 100644 index 0000000..915af0a --- /dev/null +++ b/tests/langbench/cat.pl @@ -0,0 +1,10 @@ +# One could argue this should be +# while ($foo = <>) { chomp($foo); print $foo . "\n"; } +# to match what tcl does. +# That slows it down by a factor of 2. +foreach $file (@ARGV) { + open(FD, $file); + while ($buf = <FD>) { + print $buf; + } +} diff --git a/tests/langbench/cat.py b/tests/langbench/cat.py new file mode 100644 index 0000000..3775fa3 --- /dev/null +++ b/tests/langbench/cat.py @@ -0,0 +1,16 @@ +#!/usr/bin/python +import os +import sys + +def cat(file): + f = open(file) + for line in f: + print line, + f.close() + +def main(): + for a in sys.argv: + cat(a) + +if __name__ == "__main__": + main() diff --git a/tests/langbench/cat.rb b/tests/langbench/cat.rb new file mode 100644 index 0000000..2eaf834 --- /dev/null +++ b/tests/langbench/cat.rb @@ -0,0 +1,3 @@ +while line = gets() + print line +end diff --git a/tests/langbench/cat.tcl b/tests/langbench/cat.tcl new file mode 100644 index 0000000..ebf83a5 --- /dev/null +++ b/tests/langbench/cat.tcl @@ -0,0 +1,9 @@ +proc cat {file} { + set f [open $file rb] + while {[gets $f buf] >= 0} { puts $buf } + close $f +} +fconfigure stdout -buffering full -translation binary +foreach file $argv { + cat $file +} diff --git a/tests/langbench/fib.l b/tests/langbench/fib.l new file mode 100644 index 0000000..dfb1e52 --- /dev/null +++ b/tests/langbench/fib.l @@ -0,0 +1,20 @@ + +int +fib(int n) +{ + if (n < 2) { + return (n); + } else { + return (fib(n - 1) + fib(n - 2)); + } +} + +void +main() +{ + int i; + + for (i = 0; i <= 30; ++i) { + printf("n=%d => %d\n", i, fib(i)); + } +} diff --git a/tests/langbench/fib.pl b/tests/langbench/fib.pl new file mode 100644 index 0000000..603a989 --- /dev/null +++ b/tests/langbench/fib.pl @@ -0,0 +1,11 @@ +sub fib +{ + my($n) = @_[0]; + + return $n if $n < 2; + return &fib($n - 1) + &fib($n - 2); +} + +for ($i = 0; $i <= 30; ++$i) { + printf "n=%d => %d\n", $i, &fib($i); +} diff --git a/tests/langbench/fib.py b/tests/langbench/fib.py new file mode 100644 index 0000000..f369a4c --- /dev/null +++ b/tests/langbench/fib.py @@ -0,0 +1,8 @@ +def fib(n): + if n < 2: + return n + else: + return fib(n-1) + fib(n-2) + +for i in range(30): + print "n=%d => %d" % (i, fib(i)) diff --git a/tests/langbench/fib.rb b/tests/langbench/fib.rb new file mode 100644 index 0000000..225c7bf --- /dev/null +++ b/tests/langbench/fib.rb @@ -0,0 +1,11 @@ +def fib(n) + if n < 2 + n + else + fib(n-1) + fib(n-2) + end +end + +30.times do |i| + puts "n=#{i} => #{fib(i)}" +end diff --git a/tests/langbench/fib.tcl b/tests/langbench/fib.tcl new file mode 100644 index 0000000..a107b7d --- /dev/null +++ b/tests/langbench/fib.tcl @@ -0,0 +1,11 @@ +proc fib {n} { + # Very bogus we have to do {$n - 1} to get performance. + # But if we don't this takes 35 seconds. Tcl has issues. + expr {$n < 2 ? 1 : [fib [expr {$n -2}]] + [fib [expr {$n -1}]]} +} + +set i 0 +while {$i <= 30} { + puts "n=$i => [fib $i]" + incr i +} diff --git a/tests/langbench/findtcl b/tests/langbench/findtcl new file mode 100755 index 0000000..338ab63 --- /dev/null +++ b/tests/langbench/findtcl @@ -0,0 +1,26 @@ +#!/bin/sh + +test X$TCL = X || { + echo $TCL + exit 0 +} + +# If langbench is in the bk source tree, tcl is at ../gui/tcltk/tcl +test -d ../gui/tcltk/tcl/generic && { + echo ../gui/tcltk/tcl + exit 0 +} + +# If langbench is in the tcl source tree, it is likely at tests/langbench +# or tests. +test -d ../tests -a -d ../generic && { + echo .. + exit 0 +} +test -d ../../tests -a -d ../../generic && { + echo ../.. + exit 0 +} + +echo "Can't find tcl source tree, set a path to one with TCL" 1>&2 +exit 1 diff --git a/tests/langbench/findtclsh b/tests/langbench/findtclsh new file mode 100755 index 0000000..e679716 --- /dev/null +++ b/tests/langbench/findtclsh @@ -0,0 +1,35 @@ +#!/bin/sh + +test X$TCLSH = X || { + echo $TCLSH + exit 0 +} + +# If langbench is in the bk source tree, tcl is at ../gui/tcltk/tcl +test -d ../gui/tcltk/tcl/generic && { + if [ -d C:/ ] + then echo ../gui/tcltk/tcl/win/tclsh85.exe + else echo ../gui/tcltk/tcl/unix/tclsh + fi + exit 0 +} + +# If langbench is in the tcl source tree, it is likely at tests/langbench +# or tests. +test -d ../tests -a -d ../generic && { + if [ -d C:/ ] + then echo ../win/tclsh85.exe + else echo ../unix/tclsh + fi + exit 0 +} +test -d ../../tests -a -d ../../generic && { + if [ -d C:/ ] + then echo ../../win/tclsh85.exe + else echo ../../unix/tclsh + fi + exit 0 +} + +echo "Can't find tclsh, set a path to one with TCLSH" 1>&2 +exit 1 diff --git a/tests/langbench/grep.l b/tests/langbench/grep.l new file mode 100644 index 0000000..96c255e --- /dev/null +++ b/tests/langbench/grep.l @@ -0,0 +1,15 @@ +void +main(int ac, string av[]) +{ + string buf; + int i; + FILE f; + + for (i = 1; i < ac; ++i) { + f = open(av[i], "rb"); + while (gets(f, &buf) >= 0) { + if (buf =~ /[^A-Za-z]fopen\(.*\)/) puts(buf); + } + close(f); + } +} diff --git a/tests/langbench/grep.pl b/tests/langbench/grep.pl new file mode 100644 index 0000000..9357302 --- /dev/null +++ b/tests/langbench/grep.pl @@ -0,0 +1,3 @@ +while (<>) { + print if /[^A-Za-z]fopen\(.*\)/; +} diff --git a/tests/langbench/grep.py b/tests/langbench/grep.py new file mode 100644 index 0000000..aa50e96 --- /dev/null +++ b/tests/langbench/grep.py @@ -0,0 +1,12 @@ +import os +import sys +import re + +p = re.compile('[^A-Za-z]fopen\(.*\)') +for a in sys.argv: + f = open(a) + for line in f: + m = p.search(line) + if m: + print line, + f.close() diff --git a/tests/langbench/grep.rb b/tests/langbench/grep.rb new file mode 100644 index 0000000..a13f8fe --- /dev/null +++ b/tests/langbench/grep.rb @@ -0,0 +1,4 @@ +re = Regexp.compile("[^A-Za-z]fopen\\(.*\\)") +while line = gets() + print if re =~ line +end diff --git a/tests/langbench/grep.tcl b/tests/langbench/grep.tcl new file mode 100644 index 0000000..c2ad946 --- /dev/null +++ b/tests/langbench/grep.tcl @@ -0,0 +1,12 @@ +proc grep {file} { + set f [open $file rb] + set buf "" + while {[gets $f buf] >= 0} { + if {[regexp -- {[^A-Za-z]fopen\(.*\)} $buf]} { puts $buf } + } + close $f +} +fconfigure stdout -translation binary +foreach file $argv { + grep $file +} diff --git a/tests/langbench/hash.l b/tests/langbench/hash.l new file mode 100644 index 0000000..ab10f2e --- /dev/null +++ b/tests/langbench/hash.l @@ -0,0 +1,17 @@ +void +main(int ac, string av[]) +{ + int i; + string buf; + hash h; + FILE f; + + + for (i = 1; i < ac; ++i) { + f = open(av[i], "rb"); + while (gets(f, &buf) >= 0) { + h{buf} = 1; + } + close(f); + } +} diff --git a/tests/langbench/hash.pl b/tests/langbench/hash.pl new file mode 100644 index 0000000..46e1b9a --- /dev/null +++ b/tests/langbench/hash.pl @@ -0,0 +1,5 @@ +while (<>) { + $hash{$_} = 1; +} +open(FD, "/proc/$$/status"); +while (<FD>) { print if /^Vm[RD]/; } diff --git a/tests/langbench/hash.py b/tests/langbench/hash.py new file mode 100644 index 0000000..07e8bca --- /dev/null +++ b/tests/langbench/hash.py @@ -0,0 +1,16 @@ +import os +import sys +import re + +d = {} +for a in sys.argv: + f = open(a) + for line in f: + d[line] = 1 + f.close +p = re.compile("^Vm[RD]") +f = open("/proc/%d/status" % os.getpid()) +for line in f: + m = p.match(line) + if m: + print line, diff --git a/tests/langbench/hash.rb b/tests/langbench/hash.rb new file mode 100644 index 0000000..5b30f3e --- /dev/null +++ b/tests/langbench/hash.rb @@ -0,0 +1,10 @@ +hash = {} +while line = gets() + hash[line] = 1 +end + +fd = File.open("/proc/#{$$}/status") +while $_ = fd.gets + print if $_ =~ /^Vm[RD]/ +end +fd.close diff --git a/tests/langbench/hash.tcl b/tests/langbench/hash.tcl new file mode 100644 index 0000000..0b1afa8 --- /dev/null +++ b/tests/langbench/hash.tcl @@ -0,0 +1,17 @@ +proc main {} { + global argv + + set d [dict create] + foreach file $argv { + set f [open $file rb] + while {[gets $f buf] >= 0} { + dict set d $buf 1 + } + close $f + } +} +main +set f [open "/proc/[pid]/status"] +while {[gets $f buf] >= 0} { + if {[regexp {^Vm[RD]} $buf]} { puts $buf } +} diff --git a/tests/langbench/loop.l b/tests/langbench/loop.l new file mode 100644 index 0000000..f62ff01 --- /dev/null +++ b/tests/langbench/loop.l @@ -0,0 +1,11 @@ +void +doit(int n) +{ + while (n-- > 0); +} + +void +main() +{ + doit(1000000); +} diff --git a/tests/langbench/loop.pl b/tests/langbench/loop.pl new file mode 100644 index 0000000..6f71a23 --- /dev/null +++ b/tests/langbench/loop.pl @@ -0,0 +1,2 @@ +$n = 1000000; +while ($n > 0) { $n--; } diff --git a/tests/langbench/loop.py b/tests/langbench/loop.py new file mode 100644 index 0000000..2fb1363 --- /dev/null +++ b/tests/langbench/loop.py @@ -0,0 +1,3 @@ +n = 1000000 +while n > 0: + n = n - 1 diff --git a/tests/langbench/loop.rb b/tests/langbench/loop.rb new file mode 100644 index 0000000..f6a3e16 --- /dev/null +++ b/tests/langbench/loop.rb @@ -0,0 +1,4 @@ +n = 1000000 +while n > 0 + n -= 1 +end diff --git a/tests/langbench/loop.tcl b/tests/langbench/loop.tcl new file mode 100644 index 0000000..c1de6f7 --- /dev/null +++ b/tests/langbench/loop.tcl @@ -0,0 +1,4 @@ +proc doit {n} { + while {$n > 0} { incr n -1 } +} +doit 1000000 diff --git a/tests/langbench/proc.l b/tests/langbench/proc.l new file mode 100644 index 0000000..7ac1fe6 --- /dev/null +++ b/tests/langbench/proc.l @@ -0,0 +1,20 @@ +int a(int val) { return b(val); } +int b(int val) { return c(val); } +int c(int val) { return d(val); } +int d(int val) { return e(val); } +int e(int val) { return f(val); } +int f(int val) { return g(val, 2); } +int g(int v1, int v2) { return h(v1, v2, 3); } +int h(int v1, int v2, int v3) { return i(v1, v2, v3, 4); } +int i(int v1, int v2, int v3, int v4) { return j(v1, v2, v3, v4, 5); } +int j(int v1, int v2, int v3, int v4, int v5) { return v1 + v2 + v3 + v4 + v5; } + +void +main() +{ + int n = 100000; // there are 10 procs, so .1M iterations + int x; + + while (n > 0) { x = a(n); n--; } + printf("x=%d\n", x); +} diff --git a/tests/langbench/proc.pl b/tests/langbench/proc.pl new file mode 100644 index 0000000..7ae5f2e --- /dev/null +++ b/tests/langbench/proc.pl @@ -0,0 +1,13 @@ +sub a { return &b($_[0]); } +sub b { return &c($_[0]); } +sub c { return &d($_[0]); } +sub d { return &e($_[0]); } +sub e { return &f($_[0]); } +sub f { return &g($_[0], 2); } +sub g { return &h($_[0], $_[1], 3); } +sub h { return &i($_[0], $_[1], $_[2], 4); } +sub i { return &j($_[0], $_[1], $_[2], $_[3], 5); } +sub j { return $_[0] + $_[1] + $_[2] + $_[3] + $_[4]; } +$n = 100000; +while ($n > 0) { $x = &a($n); $n--; } +print "$x\n"; diff --git a/tests/langbench/proc.py b/tests/langbench/proc.py new file mode 100644 index 0000000..726b9a5 --- /dev/null +++ b/tests/langbench/proc.py @@ -0,0 +1,28 @@ +#!/usr/bin/python + +def a(val): + return b(val) +def b(val): + return c(val) +def c(val): + return d(val) +def d(val): + return e(val) +def e(val): + return f(val) +def f(val): + return g(val, 2) +def g(v1, v2): + return h(v1, v2, 3) +def h(v1, v2, v3): + return i(v1, v2, v3, 4) +def i(v1, v2, v3, v4): + return j(v1, v2, v3, v4, 5) +def j(v1, v2, v3, v4, v5): + return v1 + v2 + v3 + v4 + v5 + +n = 100000 +while n > 0: + x = a(n) + n = n - 1 +print "x=%d" % x diff --git a/tests/langbench/proc.rb b/tests/langbench/proc.rb new file mode 100644 index 0000000..1c0aae2 --- /dev/null +++ b/tests/langbench/proc.rb @@ -0,0 +1,36 @@ +def a(i) + return b(i) +end +def b(i) + return c(i) +end +def c(i) + return d(i) +end +def d(i) + return e(i) +end +def e(i) + return f(i) +end +def f(i) + return g(i, 2) +end +def g(v1, v2) + return h(v1, v2, 3) +end +def h(v1, v2, v3) + return i(v1, v2, v3, 4) +end +def i(v1, v2, v3, v4) + return j(v1, v2, v3, v4, 5) +end +def j(v1, v2, v3, v4, v5) + return v1 + v2 + v3 + v4 + v5 +end +n = 100000; +while n > 0 + x = a(n) + n -= 1 +end +print "#{x}\n"; diff --git a/tests/langbench/proc.tcl b/tests/langbench/proc.tcl new file mode 100644 index 0000000..034190a --- /dev/null +++ b/tests/langbench/proc.tcl @@ -0,0 +1,16 @@ +proc a {val} { return [b $val] } +proc b {val} { return [c $val] } +proc c {val} { return [d $val] } +proc d {val} { return [e $val] } +proc e {val} { return [f $val] } +proc f {val} { return [g $val 2] } +proc g {v1 v2} { return [h $v1 $v2 3] } +proc h {v1 v2 v3} { return [i $v1 $v2 $v3 4] } +proc i {v1 v2 v3 v4} { return [j $v1 $v2 $v3 $v4 5] } +proc j {v1 v2 v3 v4 v5} { return [expr $v1 + $v2 + $v3 + $v4 + $v5] } +proc main {} { + set n 100000 + while {$n > 0} { set x [a $n]; incr n -1 } + puts $x +} +main diff --git a/tests/langbench/sort.l b/tests/langbench/sort.l new file mode 100644 index 0000000..f36c0e7 --- /dev/null +++ b/tests/langbench/sort.l @@ -0,0 +1,19 @@ +void +main(int ac, string av[]) +{ + int i; + FILE f; + string buf; + string l[]; + + fconfigure("stdout", buffering: "full", translation: "binary"); + for (i = 1; i < ac; ++i) { + f = open(av[i], "rb"); + while (gets(f, &buf) >= 0) { + push(&l, buf); + } + } + foreach (buf in sort(l)) { + puts(buf); + } +} diff --git a/tests/langbench/sort.pl b/tests/langbench/sort.pl new file mode 100644 index 0000000..be73936 --- /dev/null +++ b/tests/langbench/sort.pl @@ -0,0 +1,7 @@ +while (<>) { + push(@l, $_); +} + +foreach $_ (sort(@l)) { + print; +} diff --git a/tests/langbench/sort.py b/tests/langbench/sort.py new file mode 100644 index 0000000..f36bbc1 --- /dev/null +++ b/tests/langbench/sort.py @@ -0,0 +1,13 @@ +import os +import sys +import re + +l = [] +for a in sys.argv: + f = open(a) + for line in f: + l.append(line) + f.close() +l.sort() +for line in l: + print line, diff --git a/tests/langbench/sort.rb b/tests/langbench/sort.rb new file mode 100644 index 0000000..0acbf64 --- /dev/null +++ b/tests/langbench/sort.rb @@ -0,0 +1,8 @@ +l = [] +while gets + l.push($_) +end + +l.sort.each {|p| + print p +} diff --git a/tests/langbench/sort.tcl b/tests/langbench/sort.tcl new file mode 100644 index 0000000..9e353ab --- /dev/null +++ b/tests/langbench/sort.tcl @@ -0,0 +1,20 @@ +proc main {} { + global argv + + foreach file $argv { + set f [open $file rb] + + # Takes 2.7 seconds/12.3 + while {[gets $f buf] >= 0} { + lappend l $buf + } + close $f + } + + # takes 7.9 seconds/12.3 + foreach buf [lsort $l] { + puts $buf + } +} +fconfigure stdout -buffering full -translation binary +main diff --git a/tests/langbench/wc.l b/tests/langbench/wc.l new file mode 100644 index 0000000..f24ec07 --- /dev/null +++ b/tests/langbench/wc.l @@ -0,0 +1,52 @@ +string [] +wordsplit(string str) +{ + string chars[]; + string list[]; + string c, word; + int i; + + word = ""; + chars = split(str, ""); + foreach (c in chars) { + if (string("is", "space", c)) { + if (length(word) > 0) { + push(&list, word); + } + word = ""; + } else { + append(&word, c); + } + } + if (length(word) > 0) { + push(&list, word); + } + return (list); +} + +int +doit(string file) +{ + FILE f = open(file, "rb"); + string buf; + string words[]; + int n; + + while (gets(f, &buf) >= 0) { + words = wordsplit(buf); + n += llength(words); + } + close(f); + return (n); +} + +void +main(int ac, string av[]) +{ + int total, i; + + for (i = 1; i < ac; ++i) { + total += doit(av[i]); + } + printf("%d\n", total); +} diff --git a/tests/langbench/wc.pl b/tests/langbench/wc.pl new file mode 100644 index 0000000..0853908 --- /dev/null +++ b/tests/langbench/wc.pl @@ -0,0 +1,23 @@ +sub wordsplit +{ + chomp($_[0]); + @list = (); + $word = ""; + foreach $c (split(//, $_[0])) { + if ($c =~ /\s/o) { + push(@list, $word) if $word ne ""; + $word = ""; + } else { + $word .= $c; + } + } + push(@list, $word) if $word ne ""; + return @list; +} + +$n = 0; +while (<>) { + @words = &wordsplit($_); + $n += $#words + 1; +} +printf "%d\n", $n; diff --git a/tests/langbench/wc.py b/tests/langbench/wc.py new file mode 100644 index 0000000..d2a8b50 --- /dev/null +++ b/tests/langbench/wc.py @@ -0,0 +1,30 @@ +#!/usr/bin/python +import os +import sys + +def wordsplit(line): + list = [] + word = "" + for c in line: + if c.isspace(): + if len(word) > 0: + list.append(word) + word = "" + else: + word += c + if len(word) > 0: + list.append(word) + return list + +def main(): + n = 0 + for a in sys.argv[1:]: + f = open(a) + for line in f: + words = wordsplit(line) + n += len(words) + f.close() + print "%d\n" % n + +if __name__ == "__main__": + main() diff --git a/tests/langbench/wc.rb b/tests/langbench/wc.rb new file mode 100644 index 0000000..ef19635 --- /dev/null +++ b/tests/langbench/wc.rb @@ -0,0 +1,25 @@ +def wordsplit(line) + list = [] + word = "" + line.split('').each do |c| + if c =~ /\s/ + if word.length > 0 + list << word + end + word = "" + else + word += c + end + end + if word.length > 0 + list << word + end + return list +end + +n = 0 +while line = gets() + words = wordsplit(line) + n += words.length +end +printf("%d\n", n) diff --git a/tests/langbench/wc.tcl b/tests/langbench/wc.tcl new file mode 100644 index 0000000..5dc17aa --- /dev/null +++ b/tests/langbench/wc.tcl @@ -0,0 +1,36 @@ +proc wordsplit {str} { + set list {} + set word {} + foreach char [split $str {}] { + if {[string is space $char]} { + if {[string length $word] > 0} { + lappend list $word + } + set word {} + } else { + append word $char + } + } + if {[string length $word] > 0} { + lappend list $word + } + return $list +} + +proc doit {file} { + set f [open $file r] + fconfigure $f -translation binary + set buf "" + set n 0 + while {[gets $f buf] >= 0} { + set words [wordsplit $buf] + incr n [llength $words] + } + close $f + return $n +} +set total 0 +foreach file $argv { + incr total [doit $file] +} +puts $total |