lib/rgot/b.rb in rgot-0.1.5 vs lib/rgot/b.rb in rgot-0.2.0
- old
+ new
@@ -1,15 +1,15 @@
module Rgot
class B < Common
- class Options < Struct.new(
+ Options = Struct.new(
:procs,
:threads,
- :benchtime
- ); end
+ :benchtime,
+ )
attr_accessor :n
- def initialize(benchmark_module, name, opts=Options.new)
+ def initialize(benchmark_module, name, opts = Options.new)
super()
@n = 1
@module = benchmark_module
@name = name
@opts = opts
@@ -40,11 +40,11 @@
end
def run(&block)
n = 1
benchtime = (@opts.benchtime || 1).to_f
- catch(:skip) {
+ catch(:skip) do
run_n(n.to_i, block)
while !failed? && @duration < benchtime && @n < 1e9
if @duration < (benchtime / 100.0)
@n *= 100
elsif @duration < (benchtime / 10.0)
@@ -59,11 +59,11 @@
end
@n *= 1.2
end
run_n(@n.to_i, block)
end
- }
+ end
BenchmarkResult.new(n: @n, t: @duration)
end
def run_parallel
@@ -71,35 +71,35 @@
procs = (@opts.procs || 1)
threads = (@opts.threads || 1)
procs.times do
- fork {
+ fork do
Array.new(threads) {
Thread.new {
yield PB.new(bn: @n)
}.tap { |t| t.abort_on_exception = true }
}.each(&:join)
- }
+ end
end
@n *= procs * threads
Process.waitall
end
private
- def run_n(n, block=nil)
+ def run_n(n, block = nil)
GC.start
@n = n
reset_timer
start_timer
if block
block.call(self)
else
bench_method = @module.instance_method(@name).bind(@module)
if bench_method.arity == 0
path, line = bench_method.source_location
- self.skip "#{path}:#{line} `#{bench_method.name}' is not running. It's a benchmark method name, But not have argument"
+ skip "#{path}:#{line} `#{bench_method.name}' is not running. It's a benchmark method name, But not have argument"
else
bench_method.call(self)
end
end
stop_timer