Permalink
Browse files

add require performance bench

  • Loading branch information...
1 parent c14a38e commit aa54bf0c47e4bd468de53fe829b7207461b7f4f6 @akiray03 akiray03 committed Nov 5, 2012
Showing with 60 additions and 0 deletions.
  1. +60 −0 benchmark/require_performance.rb
View
60 benchmark/require_performance.rb
@@ -0,0 +1,60 @@
+#!/usr/bin/env ruby
+# --*-- encoding: utf-8 --*--
+
+require 'benchmark'
+
+WORK_DIR = "./tmp/"
+Dir.mkdir WORK_DIR unless File.exist? WORK_DIR
+MRUBY = "../bin/mruby"
+MRBC = "../bin/mrbc"
+
+AZ = ('a'..'z').to_a
+
+def dummy_class(char)
+ str = "class #{char.upcase}\n"
+ AZ.each do |m|
+ str += "def #{m}; '#{m * 100}'; end\n"
+ end
+ str += "end"
+
+ str
+end
+
+AZ.each do |char|
+ File.open(File.join(WORK_DIR, "#{char}.rb"), "w") do |fp|
+ fp.print dummy_class(char)
+ end
+end
+
+AZ.each do |char|
+ `#{MRBC} #{File.join(WORK_DIR, "#{char}.rb")}`
+end
+
+bench_rb = File.join(WORK_DIR, "00_bench_rb.rb")
+bench_mrb = File.join(WORK_DIR, "00_bench_mrb.rb")
+
+File.open(bench_rb, "w") do |fp|
+ AZ.each do |char|
+ fp.puts "require \"./#{char}.rb\""
+ end
+end
+
+File.open(bench_mrb, "w") do |fp|
+ AZ.each do |char|
+ fp.puts "require \"./#{char}.mrb\""
+ end
+end
+
+N = 1000
+
+puts "* require 'rb' file"
+puts Benchmark::CAPTION
+puts Benchmark.measure { N.times{ `#{MRUBY} #{bench_rb}` } }
+
+
+puts "* require 'mrb' file"
+puts Benchmark::CAPTION
+puts Benchmark.measure { N.times{ `#{MRUBY} #{bench_mrb}` } }
+
+
+

0 comments on commit aa54bf0

Please sign in to comment.