summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorfurunkel <[email protected]>2015-04-23 22:27:19 +0200
committerfurunkel <[email protected]>2015-04-23 22:27:19 +0200
commita96b871c463591b9e8d6f0fa541665dfc2769539 (patch)
tree0040342dd1d4baa60c0f9d2bb710940c14152c6b
parent6246483f12366818e38a5cd6070f71fefe0b8b94 (diff)
downloadmruby-a96b871c463591b9e8d6f0fa541665dfc2769539.tar.gz
mruby-a96b871c463591b9e8d6f0fa541665dfc2769539.zip
Add task for running and plotting benchmarks
-rw-r--r--.gitignore2
-rw-r--r--Rakefile2
-rw-r--r--benchmark/ao-render.rb4
-rw-r--r--tasks/benchmark.rake82
-rw-r--r--tasks/mruby_build.rake1
5 files changed, 89 insertions, 2 deletions
diff --git a/.gitignore b/.gitignore
index 75f473258..3657b105d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,6 +2,8 @@
*.bak
*.d
*.o
+benchmark/**/*.dat
+benchmark/*.pdf
*.orig
*.pdb
*.rej
diff --git a/Rakefile b/Rakefile
index fee43217c..66f54a4e2 100644
--- a/Rakefile
+++ b/Rakefile
@@ -29,6 +29,8 @@ load "#{MRUBY_ROOT}/tasks/libmruby.rake"
load "#{MRUBY_ROOT}/tasks/mrbgems_test.rake"
load "#{MRUBY_ROOT}/test/mrbtest.rake"
+load "#{MRUBY_ROOT}/tasks/benchmark.rake"
+
##############################
# generic build targets, rules
task :default => :all
diff --git a/benchmark/ao-render.rb b/benchmark/ao-render.rb
index 37bb4ad31..8212c3a13 100644
--- a/benchmark/ao-render.rb
+++ b/benchmark/ao-render.rb
@@ -5,8 +5,8 @@
# mruby version by Hideki Miura
#
-IMAGE_WIDTH = 256
-IMAGE_HEIGHT = 256
+IMAGE_WIDTH = 64
+IMAGE_HEIGHT = 64
NSUBSAMPLES = 2
NAO_SAMPLES = 8
diff --git a/tasks/benchmark.rake b/tasks/benchmark.rake
new file mode 100644
index 000000000..f682f8ee1
--- /dev/null
+++ b/tasks/benchmark.rake
@@ -0,0 +1,82 @@
+module MRuby
+ BENCHMARK_REPEAT = 2
+end
+
+$dat_files = []
+
+def bm_files
+ Dir.glob("#{MRUBY_ROOT}/benchmark/*.rb")
+end
+
+def plot_file
+ File.join(MRUBY_ROOT, 'benchmark', 'bm.pdf')
+end
+
+def plot
+ opts_file = "#{MRUBY_ROOT}/benchmark/plot.gpl"
+ opts = File.read(opts_file).each_line.to_a.map(&:strip).join(';')
+ opts += ';plot '
+
+ dat_files = $dat_files.group_by {|f| File.dirname(f).split(File::SEPARATOR)[-1]}
+
+ opts += dat_files.keys.map do |data_file|
+ %Q['-' u 2:3:4:xtic(1) w hist title columnheader(1)]
+ end.join(',')
+ opts += ';'
+
+ cmd = %Q{gnuplot -p -e "#{opts}"}
+
+ IO.popen(cmd, 'w') do |p|
+ dat_files.each do |target_name, bm_files|
+ p.puts target_name
+ bm_files.each do |bm_file|
+ puts target_name
+ p.write File.read(bm_file)
+ print File.read(bm_file)
+ end
+ p.puts "e"
+ end
+ end
+end
+
+
+MRuby.each_target do |target|
+ mruby_path = "#{target.build_dir}/bin/mruby"
+ if File.file? mruby_path
+ bm_files.each do |bm_file|
+ bm_name = File.basename bm_file, ".rb"
+
+ dat_dir = File.join('benchmark', target.name)
+ dat_file = File.join(dat_dir, "#{bm_name}.dat")
+ $dat_files << dat_file
+
+ directory dat_dir
+
+ file dat_file => [bm_file, dat_dir] do |task|
+ print bm_name
+ puts "..."
+
+ data = (0...MRuby::BENCHMARK_REPEAT).map do |n|
+ str = %x{(time -f "%e %S %U" #{mruby_path} #{bm_file}) 2>&1 >/dev/null}
+ str.split(' ').map(&:to_f)
+ end
+
+ File.open(task.name, "w") do |f|
+ data = data.map {|_,r,s| (r + s) / 2.0}
+ min = data.min
+ max = data.max
+ avg = data.inject(&:+) / data.size
+ f.puts "#{bm_name.gsub('_', '-')} #{avg} #{min} #{max}"
+ end
+ end
+ end
+ end
+end
+
+file plot_file => $dat_files do
+ plot
+end
+
+task :benchmark => plot_file do
+ plot
+end
diff --git a/tasks/mruby_build.rake b/tasks/mruby_build.rake
index 8438b6ca4..66608286d 100644
--- a/tasks/mruby_build.rake
+++ b/tasks/mruby_build.rake
@@ -8,6 +8,7 @@ module MRuby
end
def each_target(&block)
+ return to_enum(:each_target) if block.nil?
@targets.each do |key, target|
target.instance_eval(&block)
end