From 27fc66a8ca1b5fa17adf1a29ec9a497c7b10ec14 Mon Sep 17 00:00:00 2001 From: Torsten Date: Tue, 23 Jul 2019 12:07:24 +0300 Subject: [PATCH 01/11] adapted scripts for linux --- bin/rubyxc | 2 +- bin/sync_linux.sh | 2 ++ bin/{sync_rubyx.sh => sync_mac.sh} | 0 3 files changed, 3 insertions(+), 1 deletion(-) create mode 100755 bin/sync_linux.sh rename bin/{sync_rubyx.sh => sync_mac.sh} (100%) diff --git a/bin/rubyxc b/bin/rubyxc index 6a99acf2..fcf1d935 100755 --- a/bin/rubyxc +++ b/bin/rubyxc @@ -1,4 +1,4 @@ -#! /usr/bin/env ruby -I lib +#!/usr/bin/env -S ruby -I lib require 'rubygems' require 'bundler' begin diff --git a/bin/sync_linux.sh b/bin/sync_linux.sh new file mode 100755 index 00000000..ad520657 --- /dev/null +++ b/bin/sync_linux.sh @@ -0,0 +1,2 @@ +rsync -r -a -v --exclude ".git" --exclude "pi" --exclude "vendor" --exclude ".bundle" -e "ssh -l pi -p 2222" /home/torsten/ruby-x/rubyx localhost:/home/pi/ +#afplay /System/Library/Sounds/Morse.aiff diff --git a/bin/sync_rubyx.sh b/bin/sync_mac.sh similarity index 100% rename from bin/sync_rubyx.sh rename to bin/sync_mac.sh From 861fa3203f6afba9fe68027e73424d1afb4c34ca Mon Sep 17 00:00:00 2001 From: Torsten Date: Tue, 23 Jul 2019 12:08:06 +0300 Subject: [PATCH 02/11] updated qemu wuth buster Also updated website --- bin/pi_qemu.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/pi_qemu.sh b/bin/pi_qemu.sh index a831c495..94f97c9f 100755 --- a/bin/pi_qemu.sh +++ b/bin/pi_qemu.sh @@ -1 +1 @@ -qemu-system-arm -kernel pi/kernel-qemu-4.9.59-stretch -dtb pi/versatile-pb.dtb -cpu arm1176 -m 256 -M versatilepb -no-reboot -serial stdio -append 'root=/dev/sda2 panic=1 rootfstype=ext4 rw' -hda pi/raspbian-stretch-lite.qcow -net nic -net user,hostfwd=tcp::2222-:22 +qemu-system-arm -kernel pi/kernel-qemu-4.19.50-buster -dtb pi/versatile-pb.dtb -cpu arm1176 -m 256 -M versatilepb -no-reboot -serial stdio -append 'root=/dev/sda2 panic=1 rootfstype=ext4 rw' -hda pi/raspbian-buster-lite.qcow -net nic -net user,hostfwd=tcp::2222-:22 From 00bf38a0e64e7e2cb07bce65a97d1abaede217e3 Mon Sep 17 00:00:00 2001 From: Torsten Date: Tue, 23 Jul 2019 20:14:28 +0300 Subject: [PATCH 03/11] updating benchmarks on the new machine, consistent not rubyx yet --- test/bench/c/adds.c | 9 +++--- test/bench/c/calls.c | 5 ++-- test/bench/c/hello.c | 3 +- test/bench/c/itos.c | 6 ++-- test/bench/c/loop.c | 9 ------ test/bench/c/noop.c | 5 ++++ test/bench/go/{add.go => adds.go} | 2 +- test/bench/go/calls.go | 4 +-- test/bench/go/noop.go | 5 ++++ test/bench/results.md | 38 ++++++++++-------------- test/bench/ruby/adds.rb | 2 +- test/bench/ruby/calls.rb | 4 +-- test/bench/ruby/hello.rb | 3 +- test/bench/ruby/noop.rb | 1 + test/mains/source/fibo__8.rb | 3 +- test/mains/source/puts_Hello-there_11.rb | 2 +- test/mains/source/recurse-fibo__5.rb | 2 +- 17 files changed, 47 insertions(+), 56 deletions(-) delete mode 100644 test/bench/c/loop.c create mode 100644 test/bench/c/noop.c rename test/bench/go/{add.go => adds.go} (94%) create mode 100644 test/bench/go/noop.go create mode 100644 test/bench/ruby/noop.rb diff --git a/test/bench/c/adds.c b/test/bench/c/adds.c index abbb964f..082af906 100644 --- a/test/bench/c/adds.c +++ b/test/bench/c/adds.c @@ -17,11 +17,10 @@ int fibo(int n){ int main(void) { - int counter = 100352 - 352; - int counter2 = counter; - int level = 40; + int counter = 100000; int fib ; - while(counter--) { - fib = fibo(level); + while(counter) { + fib += fibo(20); + counter -= 1; } } diff --git a/test/bench/c/calls.c b/test/bench/c/calls.c index 08c8f68f..934a0049 100644 --- a/test/bench/c/calls.c +++ b/test/bench/c/calls.c @@ -10,10 +10,9 @@ int fibo_r(int n) int main(void) { - int counter = 1000; - int counter2 = counter; + int counter = 100000; int fib ; while(counter--) { - fib = fibo_r(20); + fib += fibo_r(10); } } diff --git a/test/bench/c/hello.c b/test/bench/c/hello.c index 49eddd74..f3323d27 100644 --- a/test/bench/c/hello.c +++ b/test/bench/c/hello.c @@ -2,8 +2,7 @@ int main(void) { - setbuf(stdout, NULL); /* to make it equivalent to the typed version, otherwise it caches */ - int counter = 100352 - 352; + int counter = 100000; while(counter--) { printf("Hello there\n"); } diff --git a/test/bench/c/itos.c b/test/bench/c/itos.c index 830032f9..2ad66b41 100644 --- a/test/bench/c/itos.c +++ b/test/bench/c/itos.c @@ -3,9 +3,9 @@ int main(void) { char stringa[20] ; - - int counter = 100352 - 352; + int counter = 1000; while(counter--) { - sprintf(stringa, "%i\n" , counter); + sprintf(stringa, "%i\n" , counter); } + } diff --git a/test/bench/c/loop.c b/test/bench/c/loop.c deleted file mode 100644 index d055b57d..00000000 --- a/test/bench/c/loop.c +++ /dev/null @@ -1,9 +0,0 @@ -#include - -int main(void) -{ -int counter = 100352 - 352; - while(counter) { - counter = counter - 1; - } -} diff --git a/test/bench/c/noop.c b/test/bench/c/noop.c new file mode 100644 index 00000000..402eac33 --- /dev/null +++ b/test/bench/c/noop.c @@ -0,0 +1,5 @@ + +int main(void) +{ + return 0; +} diff --git a/test/bench/go/add.go b/test/bench/go/adds.go similarity index 94% rename from test/bench/go/add.go rename to test/bench/go/adds.go index 35129e0d..93f26cda 100644 --- a/test/bench/go/add.go +++ b/test/bench/go/adds.go @@ -20,6 +20,6 @@ func main() { sum := 1 for sum < 100000 { sum += 1 - fibo( 40 ) + fibo( 20 ) } } diff --git a/test/bench/go/calls.go b/test/bench/go/calls.go index 847279f8..978380e8 100644 --- a/test/bench/go/calls.go +++ b/test/bench/go/calls.go @@ -10,8 +10,8 @@ func fib(n uint) uint { func main() { sum := 1 - for sum < 1000 { + for sum < 100000 { sum += 1 - fib( 20 ) + fib( 10 ) } } diff --git a/test/bench/go/noop.go b/test/bench/go/noop.go new file mode 100644 index 00000000..b563617c --- /dev/null +++ b/test/bench/go/noop.go @@ -0,0 +1,5 @@ +package main + +func main() { + return +} diff --git a/test/bench/results.md b/test/bench/results.md index ef9a160d..464aefdc 100644 --- a/test/bench/results.md +++ b/test/bench/results.md @@ -1,36 +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 - output hello world to measure kernel calls +add - run integer adds by linear fibonacci of 20 +call - exercise calling by recursive fibonacci of 10 +noop - a baseline that does nothing -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 -typed produced by ruby (on another machine) +All programs (apart from noop) run 1M times to minimize startup impact. +C was linked statically as dynamic linked influences times. Output was sent to /dev/null, so as +to measure the calling and not the terminal. # Results Results were measured by a ruby script. Mean and variance was measured until variance was low, -always under one percent. +always under one percent. Noop showed that program startup is a factor, so all programs loop to 1M. -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. +The machine was a virtual arm (qemu) run on a acer swift 5 (i5 8265 3.9GHz), performance roughly equivalent to a raspberry pi. +But results (in ms) should be seen as relative, not absolute. -language | loop | hello | itos | add | call -c | 0,0500 | 2,1365 | 0,2902 | 0,1245 | 0,8535 -go | 0.0485 | 4.5355 | 0.2143 | 0.0825 | 0.8769 -typed | 0,0374 | 1,2071 | 0,7263 | 0,2247 | 1,3625 +language | noop | hello | add | call +c | 45 | 100 | 72 | 591 +go | 53 | 4060 | 64 | 624 +rubyx | 0,0374 | 1,2071 | 0,2247 | 1,3625 -ruby | 0,3 | 8.882 | 0,8971 | 3,8452 - -2c | - 33 % | - 79 % | + 150% | + 80 % | + 60 % - -2r | x 10 | x 6 | + 23% | x 17 | x 26 +ruby | 1830 | 2750 | 3000 | 1900_000 Comparison with ruby, not really for speed, just to see how much leeway there is for our next layer. -Ruby startup time is 1,5695 seconds, which we'll subtract from the benches diff --git a/test/bench/ruby/adds.rb b/test/bench/ruby/adds.rb index b4fb2b02..bb58be11 100644 --- a/test/bench/ruby/adds.rb +++ b/test/bench/ruby/adds.rb @@ -14,6 +14,6 @@ end counter = 100000 while(counter > 0) do - fibo(40) + fibo(20) counter -= 1 end diff --git a/test/bench/ruby/calls.rb b/test/bench/ruby/calls.rb index 1b1274e7..3ba39352 100644 --- a/test/bench/ruby/calls.rb +++ b/test/bench/ruby/calls.rb @@ -8,9 +8,9 @@ def fibo_r( n ) end - counter = 1000 + counter = 100 while(counter > 0) do - fibo_r(20) + fibo_r(10) counter -= 1 end diff --git a/test/bench/ruby/hello.rb b/test/bench/ruby/hello.rb index a7e30f7c..d730117a 100644 --- a/test/bench/ruby/hello.rb +++ b/test/bench/ruby/hello.rb @@ -1,7 +1,6 @@ -counter = 100352 - 352; +counter = 100000; while(counter > 0) do puts "Hello there" - STDOUT.flush counter = counter - 1 end diff --git a/test/bench/ruby/noop.rb b/test/bench/ruby/noop.rb new file mode 100644 index 00000000..61c7ebff --- /dev/null +++ b/test/bench/ruby/noop.rb @@ -0,0 +1 @@ +return 0 diff --git a/test/mains/source/fibo__8.rb b/test/mains/source/fibo__8.rb index 70f8aa58..871b3099 100644 --- a/test/mains/source/fibo__8.rb +++ b/test/mains/source/fibo__8.rb @@ -1,6 +1,6 @@ class Space def main(arg) - n = 6 + n = 10 a = 0 b = 1 i = 1 @@ -13,3 +13,4 @@ class Space return result end end +#Space.new.main(1) diff --git a/test/mains/source/puts_Hello-there_11.rb b/test/mains/source/puts_Hello-there_11.rb index 59dcf17c..0d901ae2 100644 --- a/test/mains/source/puts_Hello-there_11.rb +++ b/test/mains/source/puts_Hello-there_11.rb @@ -1,5 +1,5 @@ class Space def main(arg) - return "Hello-there".putstring + return "Hello-there\n".putstring end end diff --git a/test/mains/source/recurse-fibo__5.rb b/test/mains/source/recurse-fibo__5.rb index cbcab0f4..3515a135 100644 --- a/test/mains/source/recurse-fibo__5.rb +++ b/test/mains/source/recurse-fibo__5.rb @@ -11,6 +11,6 @@ class Space end def main(arg) - return fibo_r(5) + return fibo_r(10) end end From 14c965360df7326ba1ece8f372bd56a3f063bda7 Mon Sep 17 00:00:00 2001 From: Torsten Date: Thu, 25 Jul 2019 21:23:55 +0300 Subject: [PATCH 04/11] a basic interpret command for cli part of the benchmark effort determine amount of objects --- lib/risc/interpreter.rb | 22 +++++++++++++--------- lib/rubyx/rubyxc.rb | 40 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 52 insertions(+), 10 deletions(-) diff --git a/lib/risc/interpreter.rb b/lib/risc/interpreter.rb index 58e5635c..882260aa 100644 --- a/lib/risc/interpreter.rb +++ b/lib/risc/interpreter.rb @@ -8,7 +8,8 @@ module Risc # will be executed by method execute_SlotToReg # # The Interpreter (a bit like a cpu) has a state flag, a current instruction and registers - # We collect the stdout (as a hack not to interpret the OS) + # We collect the stdout (as a hack not to interpret the OS) in a string. It can also be passed + # in to the init, as an IO # class Interpreter # fire events for changed pc and register contents @@ -18,11 +19,13 @@ module Risc attr_reader :instruction , :clock , :pc # current instruction and pc attr_reader :registers # the registers, 16 (a hash, sym -> contents) - attr_reader :stdout, :state , :flags # somewhat like the lags on a cpu, hash sym => bool (zero .. . ) + attr_reader :stdout, :state , :flags # somewhat like the flags on a cpu, hash sym => bool (zero .. . ) - #start in state :stopped and set registers to unknown - def initialize( linker ) - @stdout , @clock , @pc , @state = "", 0 , 0 , :stopped + # start in state :stopped and set registers to unknown + # Linker gives the state of the program + # Passing a stdout in (an IO, only << called) can be used to get output immediately. + def initialize( linker , stdout = "") + @stdout , @clock , @pc , @state = stdout, 0 , 0 , :stopped @registers = {} @flags = { :zero => false , :plus => false , :minus => false , :overflow => false } @@ -32,8 +35,7 @@ module Risc @linker = linker end - def start_program(linker = nil) - initialize(linker || @linker) + def start_program() init = @linker.cpu_init set_state(:running) set_pc( Position.get(init).at ) @@ -249,10 +251,12 @@ module Risc str = get_register( :r1 ) # should test length, ie r2 case str when Symbol - @stdout += str.to_s + @stdout << str.to_s + @stdout.flush if @stdout.respond_to?(:flush) return str.to_s.length when Parfait::Word - @stdout += str.to_string + @stdout << str.to_string + @stdout.flush if @stdout.respond_to?(:flush) return str.char_length else raise "NO string for putstring #{str.class}:#{str.object_id}" unless str.is_a?(Symbol) diff --git a/lib/rubyx/rubyxc.rb b/lib/rubyx/rubyxc.rb index 3483e11b..93b21a0d 100644 --- a/lib/rubyx/rubyxc.rb +++ b/lib/rubyx/rubyxc.rb @@ -1,5 +1,6 @@ require "thor" require "rubyx" +require "risc/interpreter" class RubyXC < Thor desc "compile FILE" , "Compile given FILE to binary" @@ -27,7 +28,44 @@ class RubyXC < Thor outfile = file.split("/").last.gsub(".rb" , ".o") writer.save outfile + end + + desc "interpret FILE" , "Interpret given FILE " + long_desc <<-LONGDESC + Compiles the given file to an intermediate RISC format, and runs the + Interpreter. + + RISC is the last abstract layer inside the compiler. It is in nature + very close to arm (without quirks and much smaller). + + An interpreter was originally developed for the RISC layer for debugging purposes. + Running the interpreter is about 50k slower than binary, but it can be used + to veryfy simple programs. + + No output file will be generated, the only output is generated by the + given program. + + The program must define a main method on the Space class, which will be invoked. + LONGDESC + + def interpret(file) + begin + ruby = File.read(file) + rescue + fail MalformattedArgumentError , "No such file #{file}" + end + options = { + parfait: { factory: 3*1024, }, + load_parfait: false , + } + compiler = RubyX::RubyXCompiler.new(options) + linker = compiler.ruby_to_binary(ruby, :interpreter) + + puts "interpreting #{file}" + + interpreter = Risc::Interpreter.new(linker , STDOUT ) + interpreter.start_program + interpreter.tick while(interpreter.instruction) - return outfile end end From 95af84e752927cc2af3bb9d8aceba5bc715c4176 Mon Sep 17 00:00:00 2001 From: Torsten Date: Thu, 25 Jul 2019 21:25:15 +0300 Subject: [PATCH 05/11] fixing test to pass and extract own kind of same tests to bench bench tests will need some loop, but not as large as c --- test/bench/results.md | 9 +++++---- test/bench/rubyx/hello.rb | 10 ++++++++++ test/bench/rubyx/noop.rb | 5 +++++ test/mains/source/fibo__8.rb | 2 +- test/mains/source/puts_Hello-there_11.rb | 2 +- test/mains/source/recurse-fibo__5.rb | 2 +- 6 files changed, 23 insertions(+), 7 deletions(-) create mode 100644 test/bench/rubyx/hello.rb create mode 100644 test/bench/rubyx/noop.rb diff --git a/test/bench/results.md b/test/bench/results.md index 464aefdc..f1e7f513 100644 --- a/test/bench/results.md +++ b/test/bench/results.md @@ -5,14 +5,15 @@ add - run integer adds by linear fibonacci of 20 call - exercise calling by recursive fibonacci of 10 noop - a baseline that does nothing -All programs (apart from noop) run 1M times to minimize startup impact. +All programs (apart from noop) run 100k times to minimize startup impact. C was linked statically as dynamic linked influences times. Output was sent to /dev/null, so as to measure the calling and not the terminal. # Results Results were measured by a ruby script. Mean and variance was measured until variance was low, -always under one percent. Noop showed that program startup is a factor, so all programs loop to 1M. +always under one percent. Noop showed that program startup is a factor, so all programs loop +to 100k. The machine was a virtual arm (qemu) run on a acer swift 5 (i5 8265 3.9GHz), performance roughly equivalent to a raspberry pi. But results (in ms) should be seen as relative, not absolute. @@ -21,8 +22,8 @@ But results (in ms) should be seen as relative, not absolute. language | noop | hello | add | call c | 45 | 100 | 72 | 591 go | 53 | 4060 | 64 | 624 -rubyx | 0,0374 | 1,2071 | 0,2247 | 1,3625 +rubyx | 42 | 1245 | ????? | ???? ruby | 1830 | 2750 | 3000 | 1900_000 -Comparison with ruby, not really for speed, just to see how much leeway there is for our next layer. +Comparison with ruby, not really for speed, just to see how much leeway there is in the future. diff --git a/test/bench/rubyx/hello.rb b/test/bench/rubyx/hello.rb new file mode 100644 index 00000000..1bd387fd --- /dev/null +++ b/test/bench/rubyx/hello.rb @@ -0,0 +1,10 @@ +class Space + def main(arg) + b = 2*1000 + while( b >= 1 ) + b = b - 1 + "Hello-there\n".putstring + end + return b + end +end diff --git a/test/bench/rubyx/noop.rb b/test/bench/rubyx/noop.rb new file mode 100644 index 00000000..b54859f1 --- /dev/null +++ b/test/bench/rubyx/noop.rb @@ -0,0 +1,5 @@ +class Space + def main(arg) + return 0 + end +end diff --git a/test/mains/source/fibo__8.rb b/test/mains/source/fibo__8.rb index 871b3099..7beca244 100644 --- a/test/mains/source/fibo__8.rb +++ b/test/mains/source/fibo__8.rb @@ -1,6 +1,6 @@ class Space def main(arg) - n = 10 + n = 6 a = 0 b = 1 i = 1 diff --git a/test/mains/source/puts_Hello-there_11.rb b/test/mains/source/puts_Hello-there_11.rb index 0d901ae2..59dcf17c 100644 --- a/test/mains/source/puts_Hello-there_11.rb +++ b/test/mains/source/puts_Hello-there_11.rb @@ -1,5 +1,5 @@ class Space def main(arg) - return "Hello-there\n".putstring + return "Hello-there".putstring end end diff --git a/test/mains/source/recurse-fibo__5.rb b/test/mains/source/recurse-fibo__5.rb index 3515a135..cbcab0f4 100644 --- a/test/mains/source/recurse-fibo__5.rb +++ b/test/mains/source/recurse-fibo__5.rb @@ -11,6 +11,6 @@ class Space end def main(arg) - return fibo_r(10) + return fibo_r(5) end end From 74f3420d450fc4c268f7ab826e2a607e9c8e2397 Mon Sep 17 00:00:00 2001 From: Torsten Date: Thu, 25 Jul 2019 22:36:51 +0300 Subject: [PATCH 06/11] added execute command and options execute to compile and run options to pass parfait factory levels in (as no gc) --- lib/rubyx/rubyxc.rb | 73 +++++++++++++++++++++++++++++++++------------ 1 file changed, 54 insertions(+), 19 deletions(-) diff --git a/lib/rubyx/rubyxc.rb b/lib/rubyx/rubyxc.rb index 93b21a0d..7aee2ea2 100644 --- a/lib/rubyx/rubyxc.rb +++ b/lib/rubyx/rubyxc.rb @@ -3,10 +3,12 @@ require "rubyx" require "risc/interpreter" class RubyXC < Thor + class_option :parfait , type: :numeric + + desc "compile FILE" , "Compile given FILE to binary" long_desc <<-LONGDESC - Very basic cli to compile ruby programs. - Currently only compile command supported without option. + Compile the give file name to binary object file (see long descr.) Output will be elf object file of the same name, with .o, in root directory. @@ -23,30 +25,33 @@ class RubyXC < Thor end puts "compiling #{file}" - linker = ::RubyX::RubyXCompiler.new({}).ruby_to_binary( ruby , :arm ) + linker = ::RubyX::RubyXCompiler.new(extract_options).ruby_to_binary( ruby , :arm ) writer = Elf::ObjectWriter.new(linker) outfile = file.split("/").last.gsub(".rb" , ".o") writer.save outfile + + return outfile end + desc "interpret FILE" , "Interpret given FILE " long_desc <<-LONGDESC - Compiles the given file to an intermediate RISC format, and runs the - Interpreter. + Compiles the given file to an intermediate RISC format, and runs the + Interpreter. - RISC is the last abstract layer inside the compiler. It is in nature - very close to arm (without quirks and much smaller). + RISC is the last abstract layer inside the compiler. It is in nature + very close to arm (without quirks and much smaller). - An interpreter was originally developed for the RISC layer for debugging purposes. - Running the interpreter is about 50k slower than binary, but it can be used - to veryfy simple programs. + An interpreter was originally developed for the RISC layer for debugging purposes. + Running the interpreter is about 50k slower than binary, but it can be used + to veryfy simple programs. - No output file will be generated, the only output is generated by the - given program. + No output file will be generated, the only output is generated by the + given program. - The program must define a main method on the Space class, which will be invoked. - LONGDESC + The program must define a main method on the Space class, which will be invoked. + LONGDESC def interpret(file) begin @@ -54,11 +59,7 @@ class RubyXC < Thor rescue fail MalformattedArgumentError , "No such file #{file}" end - options = { - parfait: { factory: 3*1024, }, - load_parfait: false , - } - compiler = RubyX::RubyXCompiler.new(options) + compiler = RubyX::RubyXCompiler.new(extract_options) linker = compiler.ruby_to_binary(ruby, :interpreter) puts "interpreting #{file}" @@ -68,4 +69,38 @@ class RubyXC < Thor interpreter.tick while(interpreter.instruction) end + + desc "execute FILE" , "Compile given FILE and execute resulting binary" + long_desc <<-LONGDESC + Just like the compile task, this compiles the file to an object/binary file. + + Then rubyxc will link and run the resulting object file. For this to work, + qemu needs to be set up correctly on the system. Specifically, because of + bug #13, arm-linux-gnueabihf-ld needs to exist (it's part of the cross compiled + arm binutils). + + The resulting a.out will be run via qemu-arm. This is part of the qemu "linux" package + and interprets the arm binary on the host, assuming a linux os. + + This whole approach should only be used for preliminary checking that no core-dumps + are generated by the program, or when no benchmarking (as the times will be whatever). + + For simple functional test though, it is a much much quicker way to run the binary + than transferring it to another machine. The a.out is left in place to be run again. + LONGDESC + + def execute(file) + outfile = compile(file) + system "arm-linux-gnueabihf-ld -N #{outfile}" + puts "Linked ok, now running #{file}" + system "qemu-arm ./a.out" + end + + private + def extract_options + opt = { factory: options[:parfait] || 1024 } + puts opt + return {parfait: opt} + end + end From ab87806d086695ede6ac404b5399a9a3379c8ce9 Mon Sep 17 00:00:00 2001 From: Torsten Date: Sun, 28 Jul 2019 16:42:40 +0300 Subject: [PATCH 07/11] fixes #26 only recurse to 1k then come up for air an go again. Should allow for 1M objects on a 2k stack (previously exceptions at 3.6k) --- lib/risc/collector.rb | 67 +++++++++++++++++++++++++------------ lib/risc/parfait_boot.rb | 6 ++-- test/risc/test_collector.rb | 37 +++++++++++++++++++- 3 files changed, 85 insertions(+), 25 deletions(-) diff --git a/lib/risc/collector.rb b/lib/risc/collector.rb index 9dcc1310..66c274bb 100644 --- a/lib/risc/collector.rb +++ b/lib/risc/collector.rb @@ -1,43 +1,76 @@ module Risc - # collect anything that is in the space but and reachable from init + # collect anything that is in the space and reachable (linker constants) # # The place we collect in is the position map in Position class module Collector + # Collect all object that need to be added to the binary + # This means the object_space and aby constants the linker has + # we call keep on each object, see there for details + # return all positions def self.collect_space(linker) - keep Parfait.object_space , 0 + keep Parfait.object_space linker.constants.each do |obj| - keep(obj,0) + keep(obj) end Position.positions end - def self.keep( object , depth ) + # keep "collects" the object for "keeping". Such objects get written to binary + # keeping used to be done by adding to a hash, but now the object is + # given a position, and the Position class has a hash of all positions + # (the same hash has all objects, off course) + def self.keep( object) + collection = [] + mark_1k( object , 0 , collection) + collection.each do |obj| + #puts "obj #{obj.object_id}" + keep(obj) + end + end + + # marking object that make up the binary. + # "Only" up to 1k stack depth, collect object that make up the "border" + # + # Collection is an empty arry that is passed on. Objects below 1k get added + # So basically it "should" be a return, but then we would keep creating and adding + # arrays, most of which would be empty + def self.mark_1k(object , depth , collection) return if object.nil? - return unless add_object( object , depth ) + if depth > 1000 + collection << object + return + end + return unless position!( object ) return unless object.respond_to? :has_type? type = object.get_type - keep(type , depth + 1) + mark_1k(type , depth + 1 , collection) return if object.is_a? Symbol type.names.each do |name| - keep(name , depth + 1) + mark_1k(name , depth + 1, collection) inst = object.get_instance_variable name - keep(inst , depth + 1) + #puts "getting name #{name}, val=#{inst} #{inst.object_id}" + mark_1k(inst , depth + 1, collection) end if object.is_a? Parfait::List object.each do |item| - keep(item , depth + 1) + mark_1k(item , depth + 1, collection) end end end - # Objects are data and get assembled after functions - def self.add_object( objekt , depth) + # Give the object a position. Position class keeps a list of all positions + # and associated objects. The actual position is determined later, here a + # Position object is assigned. + # + # All Objects that end up in the binary must have a Position. + # + # return if the position was assigned (true) or had been assigned already (false) + def self.position!( objekt ) return false if Position.set?(objekt) return true if objekt.is_a? ::Integer return true if objekt.is_a?( Risc::Label) - #puts message(objekt , depth) - #puts "ADD #{objekt.inspect}, #{objekt.name}" if objekt.is_a? Parfait::CallableMethod + #puts "ADD #{objekt.class.name}" unless objekt.is_a?( Parfait::Object) or objekt.is_a?( Symbol) raise "adding non parfait #{objekt.class}:#{objekt}" end @@ -46,13 +79,5 @@ module Risc true end - def self.message(object , depth) - msg = "adding #{depth}#{' ' * depth}:" - if( object.respond_to?(:rxf_reference_name)) - msg + object.rxf_reference_name.to_s - else - msg + object.class.name - end - end end end diff --git a/lib/risc/parfait_boot.rb b/lib/risc/parfait_boot.rb index 71e9d7d9..16c7cb36 100644 --- a/lib/risc/parfait_boot.rb +++ b/lib/risc/parfait_boot.rb @@ -152,8 +152,10 @@ module Parfait Data8: {}, Data16: {}, Dictionary: {i_keys: :List , i_values: :List } , - Integer: {next_integer: :Integer}, FalseClass: {}, + Factory: { for_type: :Type , next_object: :Object , + reserve: :Object , attribute_name: :Word }, + Integer: {next_integer: :Integer}, List: {indexed_length: :Integer , next_list: :List} , Message: { next_message: :Message, receiver: :Object, frame: :NamedList , return_address: :Integer, return_value: :Object, @@ -162,8 +164,6 @@ module Parfait NamedList: {}, NilClass: {}, Object: {}, - Factory: { for_type: :Type , next_object: :Object , - reserve: :Object , attribute_name: :Word }, ReturnAddress: {next_integer: :ReturnAddress}, Space: {classes: :Dictionary , types: :Dictionary , factories: :Dictionary, true_object: :TrueClass, false_object: :FalseClass , nil_object: :NilClass}, diff --git a/test/risc/test_collector.rb b/test/risc/test_collector.rb index 61926aeb..bd45435d 100644 --- a/test/risc/test_collector.rb +++ b/test/risc/test_collector.rb @@ -11,7 +11,7 @@ module Risc def test_simple_collect objects = Collector.collect_space(@linker) - assert ((400 < objects.length) or (450 > objects.length)) , objects.length.to_s + assert_equal 600 , objects.length , objects.length.to_s end def test_collect_all_types @@ -34,5 +34,40 @@ module Risc assert !position.valid? end end + def test_integer_positions + objects = Collector.collect_space(@linker) + int = Parfait.object_space.get_next_for(:Integer) + while(int) + assert Position.set?(int) , "INt #{int.object_id}" + int = int.next_integer + end + end + end + class TestBigCollector < MiniTest::Test + + def setup + opt = Parfait.default_test_options + opt[:factory] = 4000 + Parfait.boot!(opt) + Risc.boot! + @linker = Mom::MomCompiler.new.translate(:arm) + end + + def test_simple_collect + objects = Collector.collect_space(@linker) + assert_equal 20329, objects.length , objects.length.to_s + end + + def test_integer_positions + objects = Collector.collect_space(@linker) + int = Parfait.object_space.get_next_for(:Integer) + count = 0 + while(int) + count += 1 + assert Position.set?(int) , "INT #{int.object_id} , count #{count}" + int = int.next_integer + end + end + end end From 6273ab769cce1b007e38c1676e02f7c3338e5775 Mon Sep 17 00:00:00 2001 From: Torsten Date: Tue, 30 Jul 2019 13:55:29 +0300 Subject: [PATCH 08/11] redid the old benchmarks With #26 out of the way, was able to get meaningful rubyx benchmarks. Meaning loops large enough for the exec time to go significantly over the noop. Did mruby too and as expected got much lower noop --- test/bench/c/hello.c | 1 + test/bench/results.md | 22 +++++++++++----------- test/bench/ruby/calls.rb | 2 +- test/bench/ruby/hello.rb | 2 ++ test/bench/rubyx/adds.rb | 23 +++++++++++++++++++++++ test/bench/rubyx/calls.rb | 27 +++++++++++++++++++++++++++ test/bench/rubyx/hello.rb | 4 +++- test_interpreter_platform.rb | 0 8 files changed, 68 insertions(+), 13 deletions(-) create mode 100644 test/bench/rubyx/adds.rb create mode 100644 test/bench/rubyx/calls.rb delete mode 100644 test_interpreter_platform.rb diff --git a/test/bench/c/hello.c b/test/bench/c/hello.c index f3323d27..db6e3af4 100644 --- a/test/bench/c/hello.c +++ b/test/bench/c/hello.c @@ -2,6 +2,7 @@ int main(void) { + setbuf(stdout, NULL); /* to make it equivalent to the other versions, otherwise it caches */ int counter = 100000; while(counter--) { printf("Hello there\n"); diff --git a/test/bench/results.md b/test/bench/results.md index f1e7f513..74339043 100644 --- a/test/bench/results.md +++ b/test/bench/results.md @@ -7,8 +7,10 @@ noop - a baseline that does nothing All programs (apart from noop) run 100k times to minimize startup impact. -C was linked statically as dynamic linked influences times. Output was sent to /dev/null, so as -to measure the calling and not the terminal. +C was linked statically as dynamic linked influences times. +Output was sent to /dev/null, so as to measure the calling and not the terminal. +Also output was unbuffered, because that is what rubyx implements. + # Results Results were measured by a ruby script. Mean and variance was measured until variance was low, @@ -16,14 +18,12 @@ always under one percent. Noop showed that program startup is a factor, so all p to 100k. The machine was a virtual arm (qemu) run on a acer swift 5 (i5 8265 3.9GHz), performance roughly equivalent to a raspberry pi. -But results (in ms) should be seen as relative, not absolute. +Results (in ms) should be seen as relative, not absolute. -language | noop | hello | add | call -c | 45 | 100 | 72 | 591 -go | 53 | 4060 | 64 | 624 -rubyx | 42 | 1245 | ????? | ???? - -ruby | 1830 | 2750 | 3000 | 1900_000 - -Comparison with ruby, not really for speed, just to see how much leeway there is in the future. +language | noop | hello | add | call +c | 45 | 3480 | 72 | 591 +go | 53 | 4000 | 64 | 624 +rubyx | 47 | 1660 | 800 | 2000 +ruby | 1570 | 8240 | 2700 | 12370 +mruby | 108 | 11210 | 1580 | 23400 diff --git a/test/bench/ruby/calls.rb b/test/bench/ruby/calls.rb index 3ba39352..93a16379 100644 --- a/test/bench/ruby/calls.rb +++ b/test/bench/ruby/calls.rb @@ -8,7 +8,7 @@ def fibo_r( n ) end - counter = 100 + counter = 10000 while(counter > 0) do fibo_r(10) diff --git a/test/bench/ruby/hello.rb b/test/bench/ruby/hello.rb index d730117a..5ff16636 100644 --- a/test/bench/ruby/hello.rb +++ b/test/bench/ruby/hello.rb @@ -2,5 +2,7 @@ counter = 100000; while(counter > 0) do puts "Hello there" + # roughly 4 times slower with this, which is like rubyx + #STDOUT.flush counter = counter - 1 end diff --git a/test/bench/rubyx/adds.rb b/test/bench/rubyx/adds.rb new file mode 100644 index 00000000..e293e95a --- /dev/null +++ b/test/bench/rubyx/adds.rb @@ -0,0 +1,23 @@ +class Space + + def fibo_i(fib) + a = 0 + b = fib + while( a < b ) + a = a + 1 + b = b - 1 + end + return a + end + + # ran with --parfait=100000 + # (time - noop) * 25 + noop + def main(arg) + b = 4000 + while( b >= 1 ) + b = b - 1 + fibo_i(20) + end + return b + end +end diff --git a/test/bench/rubyx/calls.rb b/test/bench/rubyx/calls.rb new file mode 100644 index 00000000..813d1ef5 --- /dev/null +++ b/test/bench/rubyx/calls.rb @@ -0,0 +1,27 @@ +class Space + + def fibo_r(fib) + n = fib + a = 0 + b = 1 + i = 1 + while( i < n ) + result = a + b + a = b + b = result + i = i + 1 + end + return result + end + + # ran with --parfait=80000 + # (time - noop) * 50 + noop + def main(arg) + b = 2000 + while( b >= 1 ) + b = b - 1 + fibo_r(20) + end + return b + end +end diff --git a/test/bench/rubyx/hello.rb b/test/bench/rubyx/hello.rb index 1bd387fd..360dd808 100644 --- a/test/bench/rubyx/hello.rb +++ b/test/bench/rubyx/hello.rb @@ -1,6 +1,8 @@ class Space + # ran with --parfait=25000 + # time - noop * 10 + noop def main(arg) - b = 2*1000 + b = 10000 while( b >= 1 ) b = b - 1 "Hello-there\n".putstring diff --git a/test_interpreter_platform.rb b/test_interpreter_platform.rb deleted file mode 100644 index e69de29b..00000000 From 8eb0ba0d8108f749070f21f2e8a259f71bbaa685 Mon Sep 17 00:00:00 2001 From: Torsten Date: Tue, 30 Jul 2019 21:16:24 +0300 Subject: [PATCH 09/11] fix benchmarks up to 20 recursive fibo had mixed add and calls for rubyx --- test/bench/c/calls.c | 4 ++-- test/bench/go/calls.go | 4 ++-- test/bench/results.md | 14 +++++++------- test/bench/ruby/calls.rb | 4 ++-- test/bench/rubyx/adds.rb | 19 +++++++++++-------- test/bench/rubyx/calls.rb | 29 ++++++++++++----------------- 6 files changed, 36 insertions(+), 38 deletions(-) diff --git a/test/bench/c/calls.c b/test/bench/c/calls.c index 934a0049..afd751ce 100644 --- a/test/bench/c/calls.c +++ b/test/bench/c/calls.c @@ -10,9 +10,9 @@ int fibo_r(int n) int main(void) { - int counter = 100000; + int counter = 1000; int fib ; while(counter--) { - fib += fibo_r(10); + fib += fibo_r(20); } } diff --git a/test/bench/go/calls.go b/test/bench/go/calls.go index 978380e8..847279f8 100644 --- a/test/bench/go/calls.go +++ b/test/bench/go/calls.go @@ -10,8 +10,8 @@ func fib(n uint) uint { func main() { sum := 1 - for sum < 100000 { + for sum < 1000 { sum += 1 - fib( 10 ) + fib( 20 ) } } diff --git a/test/bench/results.md b/test/bench/results.md index 74339043..5c93dc85 100644 --- a/test/bench/results.md +++ b/test/bench/results.md @@ -2,10 +2,10 @@ hello - output hello world to measure kernel calls add - run integer adds by linear fibonacci of 20 -call - exercise calling by recursive fibonacci of 10 +call - exercise calling by recursive fibonacci of 20 noop - a baseline that does nothing -All programs (apart from noop) run 100k times to minimize startup impact. +Hello and add run 100k times, calls 1k, to minimize startup impact. C was linked statically as dynamic linked influences times. Output was sent to /dev/null, so as to measure the calling and not the terminal. @@ -22,8 +22,8 @@ Results (in ms) should be seen as relative, not absolute. language | noop | hello | add | call -c | 45 | 3480 | 72 | 591 -go | 53 | 4000 | 64 | 624 -rubyx | 47 | 1660 | 800 | 2000 -ruby | 1570 | 8240 | 2700 | 12370 -mruby | 108 | 11210 | 1580 | 23400 +c | 45 | 3480 | 150 | 1400 +go | 53 | 4000 | 64 | 740 +rubyx | 43 | 1560 | 1800 | 16500 +ruby | 1570 | 8240 | 2290 | 17800 +mruby | 86 | 11210 | 1580 | 26500 diff --git a/test/bench/ruby/calls.rb b/test/bench/ruby/calls.rb index 93a16379..a3aa2c4c 100644 --- a/test/bench/ruby/calls.rb +++ b/test/bench/ruby/calls.rb @@ -8,9 +8,9 @@ def fibo_r( n ) end - counter = 10000 + counter = 100 while(counter > 0) do - fibo_r(10) + fibo_r(20) counter -= 1 end diff --git a/test/bench/rubyx/adds.rb b/test/bench/rubyx/adds.rb index e293e95a..2519f5d6 100644 --- a/test/bench/rubyx/adds.rb +++ b/test/bench/rubyx/adds.rb @@ -1,19 +1,22 @@ class Space def fibo_i(fib) + n = fib a = 0 - b = fib - while( a < b ) - a = a + 1 - b = b - 1 + b = 1 + i = 1 + while( i < n ) + result = a + b + a = b + b = result + i = i + 1 end - return a + return result end - # ran with --parfait=100000 - # (time - noop) * 25 + noop + # ran with --parfait=40000 def main(arg) - b = 4000 + b = 1000 while( b >= 1 ) b = b - 1 fibo_i(20) diff --git a/test/bench/rubyx/calls.rb b/test/bench/rubyx/calls.rb index 813d1ef5..3a6693c7 100644 --- a/test/bench/rubyx/calls.rb +++ b/test/bench/rubyx/calls.rb @@ -1,27 +1,22 @@ class Space - def fibo_r(fib) - n = fib - a = 0 - b = 1 - i = 1 - while( i < n ) - result = a + b - a = b - b = result - i = i + 1 - end - return result + def fibo_r( n ) + if( n < 2 ) + return n + end + a = fibo_r(n - 1) + d = fibo_r(n - 2) + return a + d end - # ran with --parfait=80000 - # (time - noop) * 50 + noop + # ran with --parfait=70000 def main(arg) - b = 2000 + b = 2 + res = 0 while( b >= 1 ) b = b - 1 - fibo_r(20) + res = fibo_r(20) end - return b + return res end end From 6b1c316f04310efaeaa6b4c0592f029055d19793 Mon Sep 17 00:00:00 2001 From: Torsten Date: Wed, 31 Jul 2019 21:18:03 +0300 Subject: [PATCH 10/11] add simple loop bench fiddled with run numbers a bit recording times with noop removed results slightly worse than hoped --- test/bench/c/adds.c | 6 ++---- test/bench/c/calls.c | 2 +- test/bench/c/hello.c | 2 +- test/bench/c/loop.c | 7 +++++++ test/bench/go/adds.go | 6 ++++-- test/bench/go/calls.go | 2 +- test/bench/go/hello.go | 2 +- test/bench/go/loop.go | 2 +- test/bench/results.md | 21 +++++++++++---------- test/bench/ruby/adds.rb | 4 ++-- test/bench/ruby/hello.rb | 4 ++-- test/bench/ruby/loop.rb | 4 ++-- test/bench/rubyx/adds.rb | 4 ++-- test/bench/rubyx/calls.rb | 4 ++-- test/bench/rubyx/hello.rb | 1 - test/bench/rubyx/loop.rb | 11 +++++++++++ test/bench/runner.rb | 2 +- 17 files changed, 51 insertions(+), 33 deletions(-) create mode 100644 test/bench/c/loop.c create mode 100644 test/bench/rubyx/loop.rb diff --git a/test/bench/c/adds.c b/test/bench/c/adds.c index 082af906..b380c277 100644 --- a/test/bench/c/adds.c +++ b/test/bench/c/adds.c @@ -1,5 +1,3 @@ -#include - int fibo(int n){ int result; int a = 0; @@ -17,10 +15,10 @@ int fibo(int n){ int main(void) { - int counter = 100000; + int counter = 50000; int fib ; while(counter) { - fib += fibo(20); + fib = fibo(40); counter -= 1; } } diff --git a/test/bench/c/calls.c b/test/bench/c/calls.c index afd751ce..3ed3c4c2 100644 --- a/test/bench/c/calls.c +++ b/test/bench/c/calls.c @@ -10,7 +10,7 @@ int fibo_r(int n) int main(void) { - int counter = 1000; + int counter = 100; int fib ; while(counter--) { fib += fibo_r(20); diff --git a/test/bench/c/hello.c b/test/bench/c/hello.c index db6e3af4..88a7e930 100644 --- a/test/bench/c/hello.c +++ b/test/bench/c/hello.c @@ -3,7 +3,7 @@ int main(void) { setbuf(stdout, NULL); /* to make it equivalent to the other versions, otherwise it caches */ - int counter = 100000; + int counter = 10000; while(counter--) { printf("Hello there\n"); } diff --git a/test/bench/c/loop.c b/test/bench/c/loop.c new file mode 100644 index 00000000..e98979b8 --- /dev/null +++ b/test/bench/c/loop.c @@ -0,0 +1,7 @@ +int main(void) +{ + int counter = 1000000; + while(counter) { + counter -= 1; + } +} diff --git a/test/bench/go/adds.go b/test/bench/go/adds.go index 93f26cda..2fcf5c65 100644 --- a/test/bench/go/adds.go +++ b/test/bench/go/adds.go @@ -18,8 +18,10 @@ func fibo(n int ) int { func main() { sum := 1 - for sum < 100000 { + res := 0 + for sum < 50000 { sum += 1 - fibo( 20 ) + res = fibo( 40 ) } + res += 1 } diff --git a/test/bench/go/calls.go b/test/bench/go/calls.go index 847279f8..66c2c08c 100644 --- a/test/bench/go/calls.go +++ b/test/bench/go/calls.go @@ -10,7 +10,7 @@ func fib(n uint) uint { func main() { sum := 1 - for sum < 1000 { + for sum < 100 { sum += 1 fib( 20 ) } diff --git a/test/bench/go/hello.go b/test/bench/go/hello.go index 53e3d830..a20d46a3 100644 --- a/test/bench/go/hello.go +++ b/test/bench/go/hello.go @@ -4,7 +4,7 @@ import "fmt" func main() { sum := 1 - for sum < 100000 { + for sum < 10000 { sum += 1 fmt.Println("Hi there") } diff --git a/test/bench/go/loop.go b/test/bench/go/loop.go index e7673f18..a4f4eb02 100644 --- a/test/bench/go/loop.go +++ b/test/bench/go/loop.go @@ -2,7 +2,7 @@ package main func main() { sum := 1 - for sum < 100000 { + for sum < 1000000 { sum += 1 } } diff --git a/test/bench/results.md b/test/bench/results.md index 5c93dc85..3d17ecb1 100644 --- a/test/bench/results.md +++ b/test/bench/results.md @@ -1,11 +1,13 @@ # Benchmarks hello - output hello world to measure kernel calls -add - run integer adds by linear fibonacci of 20 +add - run integer adds by linear fibonacci of 40 call - exercise calling by recursive fibonacci of 20 noop - a baseline that does nothing +loop - just counts down, from 1M -Hello and add run 100k times, calls 1k, to minimize startup impact. +Loop, Hello, add and call run 1M , 50k, 10k and 100 respectively, +to minimize startup impact. C was linked statically as dynamic linked influences times. Output was sent to /dev/null, so as to measure the calling and not the terminal. @@ -14,16 +16,15 @@ Also output was unbuffered, because that is what rubyx implements. # Results Results were measured by a ruby script. Mean and variance was measured until variance was low, -always under one percent. Noop showed that program startup is a factor, so all programs loop -to 100k. +always under one percent. Noop showed that program startup is a factor, so all programs loop from 10 to 50k. The machine was a virtual arm (qemu) run on a acer swift 5 (i5 8265 3.9GHz), performance roughly equivalent to a raspberry pi. Results (in ms) should be seen as relative, not absolute. -language | noop | hello | add | call -c | 45 | 3480 | 150 | 1400 -go | 53 | 4000 | 64 | 740 -rubyx | 43 | 1560 | 1800 | 16500 -ruby | 1570 | 8240 | 2290 | 17800 -mruby | 86 | 11210 | 1580 | 26500 +language | noop | hello | add | call | loop +c | 55 | 380 | 88 | 135 | 6 +go | 52 | 450 | 9 | 77 | 2 +rubyx | 42 | 200 | 1700 | 1700 | 480 +ruby | 1570 | 650 | 1090 | 1500 | 180 +mruby | 86 | 1200 | 1370 | 2700 | 300 diff --git a/test/bench/ruby/adds.rb b/test/bench/ruby/adds.rb index bb58be11..db4fdeec 100644 --- a/test/bench/ruby/adds.rb +++ b/test/bench/ruby/adds.rb @@ -11,9 +11,9 @@ def fibo( n) return result end - counter = 100000 + counter = 50000 while(counter > 0) do - fibo(20) + fibo(40) counter -= 1 end diff --git a/test/bench/ruby/hello.rb b/test/bench/ruby/hello.rb index 5ff16636..afa03db8 100644 --- a/test/bench/ruby/hello.rb +++ b/test/bench/ruby/hello.rb @@ -1,8 +1,8 @@ -counter = 100000; +counter = 10000; while(counter > 0) do puts "Hello there" # roughly 4 times slower with this, which is like rubyx - #STDOUT.flush + STDOUT.flush counter = counter - 1 end diff --git a/test/bench/ruby/loop.rb b/test/bench/ruby/loop.rb index 5a89d936..c0405c93 100644 --- a/test/bench/ruby/loop.rb +++ b/test/bench/ruby/loop.rb @@ -1,5 +1,5 @@ -counter = 100000 +counter = 1000000 while(counter > 0) do - counter = counter - 1 + counter -= 1 end diff --git a/test/bench/rubyx/adds.rb b/test/bench/rubyx/adds.rb index 2519f5d6..4f726430 100644 --- a/test/bench/rubyx/adds.rb +++ b/test/bench/rubyx/adds.rb @@ -14,12 +14,12 @@ class Space return result end - # ran with --parfait=40000 + # ran with --parfait=80000 def main(arg) b = 1000 while( b >= 1 ) b = b - 1 - fibo_i(20) + fibo_i(40) end return b end diff --git a/test/bench/rubyx/calls.rb b/test/bench/rubyx/calls.rb index 3a6693c7..bfbcb58b 100644 --- a/test/bench/rubyx/calls.rb +++ b/test/bench/rubyx/calls.rb @@ -5,8 +5,8 @@ class Space return n end a = fibo_r(n - 1) - d = fibo_r(n - 2) - return a + d + b = fibo_r(n - 2) + return a + b end # ran with --parfait=70000 diff --git a/test/bench/rubyx/hello.rb b/test/bench/rubyx/hello.rb index 360dd808..f18b59f5 100644 --- a/test/bench/rubyx/hello.rb +++ b/test/bench/rubyx/hello.rb @@ -1,6 +1,5 @@ class Space # ran with --parfait=25000 - # time - noop * 10 + noop def main(arg) b = 10000 while( b >= 1 ) diff --git a/test/bench/rubyx/loop.rb b/test/bench/rubyx/loop.rb new file mode 100644 index 00000000..22807be3 --- /dev/null +++ b/test/bench/rubyx/loop.rb @@ -0,0 +1,11 @@ +class Space + + # ran with --parfait=101000 + def main(arg) + b = 100000 + while( b >= 1 ) + b = b - 1 + end + return b + end +end diff --git a/test/bench/runner.rb b/test/bench/runner.rb index 2d998dd8..a07d5593 100644 --- a/test/bench/runner.rb +++ b/test/bench/runner.rb @@ -17,7 +17,7 @@ class Stats def show #puts "no per var" - puts "#{@n} #{@mean} #{@variance / @n}" + puts "#{@n} #{(@mean*1000).truncate(1)} #{((@variance / @n)*100).truncate(2)}" end end class Runner From 7daf015ed2ff87e3c9c60ac50b0af8ac2d94fc26 Mon Sep 17 00:00:00 2001 From: Torsten Date: Thu, 1 Aug 2019 09:20:08 +0300 Subject: [PATCH 11/11] small refactor --- lib/parfait/factory.rb | 11 +++++------ test/bench/results.md | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/parfait/factory.rb b/lib/parfait/factory.rb index 783c504e..43b93548 100644 --- a/lib/parfait/factory.rb +++ b/lib/parfait/factory.rb @@ -50,16 +50,15 @@ # and rebuilt the reserve (get_next already instantiates the reserve) # def get_more - first_object = get_chain - link = first_object + self.reserve = get_chain + last_link = self.reserve count = Factory.reserve_size while(count > 0) - link = get_next_for(link) + last_link = get_next_for(last_link) count -= 1 end - self.next_object = get_next_for(link) - set_next_for( link , nil ) - self.reserve = first_object + self.next_object = get_next_for(last_link) + set_next_for( last_link , nil ) self end diff --git a/test/bench/results.md b/test/bench/results.md index 3d17ecb1..22e3b4b2 100644 --- a/test/bench/results.md +++ b/test/bench/results.md @@ -16,7 +16,7 @@ Also output was unbuffered, because that is what rubyx implements. # Results Results were measured by a ruby script. Mean and variance was measured until variance was low, -always under one percent. Noop showed that program startup is a factor, so all programs loop from 10 to 50k. +always under one percent. Noop showed that program startup is a factor, so all programs loop somewhere from 1M to 100, depending on how intensive. The machine was a virtual arm (qemu) run on a acer swift 5 (i5 8265 3.9GHz), performance roughly equivalent to a raspberry pi. Results (in ms) should be seen as relative, not absolute.