lib/benchmark_driver.rb in benchmark_driver-0.2.0 vs lib/benchmark_driver.rb in benchmark_driver-0.2.1
- old
+ new
@@ -6,11 +6,11 @@
MEASURE_TYPES = %w[loop_count ips]
DEFAULT_LOOP_COUNT = 100_000
DEFAULT_IPS_DURATION = 1
# @param [String] measure_type - "loop_count"|"ips"
- # @param [Integer] measure_num - Loop count for "loop_type", duration seconds for "ips"
+ # @param [Integer,nil] measure_num - Loop count for "loop_type", duration seconds for "ips"
# @param [Array<String>] execs - ["path1", "path2"] or `["ruby1::path1", "ruby2::path2"]`
# @param [Boolean] verbose
def initialize(measure_type: 'loop_count', measure_num: nil, execs: ['ruby'], verbose: false)
unless MEASURE_TYPES.include?(measure_type)
abort "unsupported measure type: #{measure_type.dump}"
@@ -76,11 +76,11 @@
measure_script(exec.path, benchmark.benchmark_script(iterations)) -
measure_script(exec.path, benchmark.overhead_script(iterations))
end
def measure_script(ruby, script)
- Tempfile.create do |f|
+ Tempfile.create(File.basename(__FILE__)) do |f|
f.write(script)
f.close
cmd = "#{ruby} #{f.path}"
Benchmark.measure { system(cmd, out: File::NULL) }.real
@@ -137,22 +137,22 @@
end
def overhead_script(iterations)
<<-RUBY
#{@prelude}
-i = 0
-while i < #{iterations}
- i += 1
+__benchmark_driver_i = 0
+while __benchmark_driver_i < #{iterations}
+ __benchmark_driver_i += 1
end
RUBY
end
def benchmark_script(iterations)
<<-RUBY
#{@prelude}
-i = 0
-while i < #{iterations}
- i += 1
+__benchmark_driver_i = 0
+while __benchmark_driver_i < #{iterations}
+ __benchmark_driver_i += 1
#{@benchmark}
end
RUBY
end
end