summaryrefslogtreecommitdiffhomepage
path: root/benchmark
diff options
context:
space:
mode:
authorfurunkel <[email protected]>2015-04-24 13:40:54 +0200
committerfurunkel <[email protected]>2015-04-24 13:40:54 +0200
commit465d7a23c89d385e1c419a7bd1546b0bf41bf097 (patch)
tree8997d1f325cc57338647ba4b783723f583b1b975 /benchmark
parent96d66f6d241374cd5b4423aab8e0a6289fdf697c (diff)
downloadmruby-465d7a23c89d385e1c419a7bd1546b0bf41bf097.tar.gz
mruby-465d7a23c89d385e1c419a7bd1546b0bf41bf097.zip
Add build files for benchmarkings; add mandelbrot benchmark
Diffstat (limited to 'benchmark')
-rw-r--r--benchmark/bm_so_mandelbrot.rb64
-rw-r--r--benchmark/build_config_boxing.rb28
-rw-r--r--benchmark/build_config_cc.rb13
-rw-r--r--benchmark/fib.rb (renamed from benchmark/fib39.rb)3
-rw-r--r--benchmark/plot.gpl5
5 files changed, 111 insertions, 2 deletions
diff --git a/benchmark/bm_so_mandelbrot.rb b/benchmark/bm_so_mandelbrot.rb
new file mode 100644
index 000000000..dd1d75ba1
--- /dev/null
+++ b/benchmark/bm_so_mandelbrot.rb
@@ -0,0 +1,64 @@
+# The Computer Language Benchmarks Game
+# http://shootout.alioth.debian.org/
+#
+# contributed by Karl von Laudermann
+# modified by Jeremy Echols
+size = 1000 # ARGV[0].to_i
+
+puts "P4\n#{size} #{size}"
+
+ITER = 49 # Iterations - 1 for easy for..in looping
+LIMIT_SQUARED = 4.0 # Presquared limit
+
+byte_acc = 0
+bit_num = 0
+
+count_size = size - 1 # Precomputed size for easy for..in looping
+def id(x)
+ x
+end
+
+# For..in loops are faster than .upto, .downto, .times, etc.
+for y in 0..count_size
+ for x in 0..count_size
+ zr = 0.0
+ zi = 0.0
+ cr = (2.0*x/size)-1.5
+ ci = (2.0*y/size)-1.0
+ escape = false
+
+ # To make use of the for..in code, we use a dummy variable,
+ # like one would in C
+ for dummy in 0..ITER
+ tr = zr*zr - zi*zi + cr
+ ti = 2*zr*zi + ci
+ zr, zi = tr, ti
+
+ if (zr*zr+zi*zi) > LIMIT_SQUARED
+ escape = true
+ break
+ end
+ end
+
+# byte_acc = (byte_acc << 1) | (escape ? 0b0 : 0b1)
+ byte_acc = (byte_acc * 2) | (escape ? 0b0 : 0b1)
+# byte_acc = (byte_acc * 2) + (escape ? 0b0 : 0b1)
+# byte_acc = (byte_acc * 2) + 1
+
+ bit_num += 1
+
+ # Code is very similar for these cases, but using separate blocks
+ # ensures we skip the shifting when it's unnecessary, which is most cases.
+ if (bit_num == 8)
+# print byte_acc.chr
+ byte_acc = 0
+ bit_num = 0
+ elsif (x == count_size)
+ byte_acc <<= (8 - bit_num)
+# byte_acc = byte_acc << (8 - bit_num)
+# print byte_acc.chr
+ byte_acc = 0
+ bit_num = 0
+ end
+ end
+end
diff --git a/benchmark/build_config_boxing.rb b/benchmark/build_config_boxing.rb
new file mode 100644
index 000000000..b478c9005
--- /dev/null
+++ b/benchmark/build_config_boxing.rb
@@ -0,0 +1,28 @@
+MRuby::Build.new do |conf|
+ toolchain :gcc
+end
+
+MRuby::Build.new('no_boxing') do |conf|
+ toolchain :gcc
+
+ conf.gembox 'default'
+end
+
+MRuby::Build.new('word_boxing') do |conf|
+ toolchain :gcc
+
+ conf.gembox 'default'
+ conf.compilers.each do |c|
+ c.defines += %w(MRB_WORD_BOXING)
+ end
+end
+
+MRuby::Build.new('nan_boxing') do |conf|
+ toolchain :gcc
+
+ conf.gembox 'default'
+ conf.compilers.each do |c|
+ c.defines += %w(MRB_NAN_BOXING)
+ end
+end
+
diff --git a/benchmark/build_config_cc.rb b/benchmark/build_config_cc.rb
new file mode 100644
index 000000000..56d725bc7
--- /dev/null
+++ b/benchmark/build_config_cc.rb
@@ -0,0 +1,13 @@
+MRuby::Build.new do |conf|
+ toolchain :gcc
+end
+
+MRuby::Build.new('gcc') do |conf|
+ toolchain :gcc
+ conf.gembox 'default'
+end
+
+MRuby::Build.new('clang') do |conf|
+ toolchain :clang
+ conf.gembox 'default'
+end
diff --git a/benchmark/fib39.rb b/benchmark/fib.rb
index d5565b779..4b395f9cc 100644
--- a/benchmark/fib39.rb
+++ b/benchmark/fib.rb
@@ -1,8 +1,7 @@
-# Fib 39
def fib n
return n if n < 2
fib(n-2) + fib(n-1)
end
-puts fib(39)
+puts fib(37)
diff --git a/benchmark/plot.gpl b/benchmark/plot.gpl
new file mode 100644
index 000000000..639674d68
--- /dev/null
+++ b/benchmark/plot.gpl
@@ -0,0 +1,5 @@
+set yrange [0:]
+set terminal pdf
+set xtics rotate by -45
+set style histogram errorbars gap 2 lw 1
+set style fill solid border -1