diff --git a/lib/soml/parfait/integer.soml b/lib/soml/parfait/integer.soml index 44ec1d71..ea010f8a 100644 --- a/lib/soml/parfait/integer.soml +++ b/lib/soml/parfait/integer.soml @@ -105,6 +105,7 @@ class Integer < Value Word to_s() Word start = " " + start.set_length(0) return as_string( start ) end diff --git a/test/bench/fibo.c b/test/bench/adds.c similarity index 80% rename from test/bench/fibo.c rename to test/bench/adds.c index 352adfc4..beedd796 100644 --- a/test/bench/fibo.c +++ b/test/bench/adds.c @@ -17,13 +17,11 @@ int fibo(int n){ int main(void) { - int counter = 1000000; + int counter = 98304 + 1696; int counter2 = counter; int level = 40; int fib ; while(counter--) { fib = fibo(level); } - printf("%i times fib %d \n",counter2 , level); - } diff --git a/test/bench/calls.c b/test/bench/calls.c new file mode 100644 index 00000000..08c8f68f --- /dev/null +++ b/test/bench/calls.c @@ -0,0 +1,19 @@ +#include + +int fibo_r(int n) +{ + if ( n < 2 ) + return n; + else + return ( fibo_r(n-1) + fibo_r(n-2) ); +} + +int main(void) +{ + int counter = 1000; + int counter2 = counter; + int fib ; + while(counter--) { + fib = fibo_r(20); + } +} diff --git a/test/bench/hello.c b/test/bench/hello.c index 35a9d49c..494f8431 100644 --- a/test/bench/hello.c +++ b/test/bench/hello.c @@ -2,7 +2,7 @@ int main(void) { - int counter = 1000000; + int counter = 98304 + 1696; while(counter--) { printf("Hello there\n"); } diff --git a/test/bench/hello0.c b/test/bench/hello0.c deleted file mode 100644 index 35a9d49c..00000000 --- a/test/bench/hello0.c +++ /dev/null @@ -1,9 +0,0 @@ -#include - -int main(void) -{ - int counter = 1000000; - while(counter--) { - printf("Hello there\n"); - } -} diff --git a/test/bench/itos.c b/test/bench/itos.c new file mode 100644 index 00000000..d3e92173 --- /dev/null +++ b/test/bench/itos.c @@ -0,0 +1,11 @@ +#include + +int main(void) +{ + char stringa[20] ; + + int counter = 98304 + 1696; + while(counter--) { + sprintf(stringa, "%i\n" , counter); + } +} diff --git a/test/bench/null.c b/test/bench/null.c index 85a94047..22a6016b 100644 --- a/test/bench/null.c +++ b/test/bench/null.c @@ -2,5 +2,8 @@ int main(void) { - return 1; +int counter = 98304 + 1696; + while(counter--) { + counter = counter; + } } diff --git a/test/bench/puti.c b/test/bench/puti.c deleted file mode 100644 index f3eea358..00000000 --- a/test/bench/puti.c +++ /dev/null @@ -1,9 +0,0 @@ -#include - -int main(void) -{ - int counter = 1000000; - while(counter--) { - printf("%i\n" , counter); - } -} diff --git a/test/bench/results.md b/test/bench/results.md new file mode 100644 index 00000000..1b70c29e --- /dev/null +++ b/test/bench/results.md @@ -0,0 +1,28 @@ +# Benchmarks + +loop - program does empty loop of same size as hello +hello - output hello world (to dev/null) to measure kernel calls (not terminal speed) +itos - convert integers from 1 to 100000 to string +add - run integer adds by linear fibonacci of 40 +call - exercise calling by recursive fibonacci of 20 + +Hello and puti and add run 100_000 iterations per program invocation to remove startup overhead. +Call only has 10000 iterations, as it much slower + +Gcc used to compile c on the machine +soml produced by ruby (on another machine) + +# Results + +Results were measured by a ruby script. Mean and variance was measured until variance was low, +usually under one percent. + +The machine was a virtual arm run on a powerbook, performance roughly equivalent to a raspberry pi. +But results should be seen as relative, not absolute. + + +language | loop | hello | itos | add | call +c | 0.1530 | 0.3422 | 0.871 | 0.3968 | 2.5913 +c variance| 0.0018  | 0.010 | 0.027 | 0.0013 | 0.0058 +soml | 0.1130 | 3.5778 | 3.772 | 0.6856 | 4.0325 +variance | 0.0009 | 0.021 | 0.001 | 0.0014 | 0.0035 diff --git a/test/bench/runner.rb b/test/bench/runner.rb index da4817d7..5abc2f56 100644 --- a/test/bench/runner.rb +++ b/test/bench/runner.rb @@ -16,7 +16,8 @@ class Stats end def show #puts "no per var" - puts "#{@n} #{@mean} #{@variance}" + + puts "#{@n} #{@mean} #{@variance / @n}" end end class Runner @@ -25,12 +26,14 @@ class Runner @cmd = ARGV[0] end def run - { once } while true + while true + once + end end def once GC.disable - took = Benchmark.measure { %x("#{@cmd}")}.real + took = Benchmark.measure { %x(#{@cmd} > /dev/null)}.real GC.enable @stats.add took @stats.show diff --git a/test/soml/helper.rb b/test/soml/helper.rb index 07ffc612..ac2165ad 100644 --- a/test/soml/helper.rb +++ b/test/soml/helper.rb @@ -29,6 +29,8 @@ module RuntimeTests def check ret = nil load_program + check_remote ret + exit interpreter = Register::Interpreter.new interpreter.start @machine.init count = 0 @@ -59,9 +61,9 @@ module RuntimeTests return unless box = connected load_program file = write_object_file - print "\nfile #{file} " r_file = file.sub("./" , "salama/") box.file_upload file , r_file + print "\nfile #{file} " box.ld "-N", r_file begin #need to rescue here as rye throws if no return 0 ret = box.aout # and we use return to mean something diff --git a/test/soml/parfait/test_integer.rb b/test/soml/parfait/test_integer.rb index aac984b5..5c4912fd 100644 --- a/test/soml/parfait/test_integer.rb +++ b/test/soml/parfait/test_integer.rb @@ -179,6 +179,15 @@ five.putstring()" @stdout = " 21" check 21 end + def test_fib20_1000 + @main = "int count = 1000 + while_plus( count - 1) + 20.fibr( ) + count = count - 1 + end + return count" + check 0 + end def test_fibw8 @main = "int fib = 8.fibw( ) @@ -193,9 +202,8 @@ five.putstring()" check 6765 end - def pest_fib40_1000000 - @main = "int count = 999424 - count = count + 576 + def test_fib40_100000 + @main = "int count = 100352 - 352 while_plus( count - 1) 40.fibw( ) count = count - 1 @@ -203,4 +211,21 @@ five.putstring()" return count" check 0 end + def test_itos_100000 + @main = "int count = 100352 - 352 + while_plus( count - 1) + count.to_s( ) + count = count - 1 + end + return count" + check 0 + end + def test_loop_100000 + @main = "int count = 100352 - 352 + while_plus( count - 1) + count = count - 1 + end + return count" + check 0 + end end diff --git a/test/soml/parfait/test_word.rb b/test/soml/parfait/test_word.rb index 4619d016..745dd73f 100644 --- a/test/soml/parfait/test_word.rb +++ b/test/soml/parfait/test_word.rb @@ -177,4 +177,17 @@ return w.char_length HERE check 4 end + + def test_puts_100000 + @main = <