Class: BenchPress::Runnable
- Inherits:
-
Object
- Object
- BenchPress::Runnable
- Defined in:
- lib/bench_press/runnable.rb
Instance Attribute Summary collapse
-
#code_block ⇒ Object
readonly
Returns the value of attribute code_block.
-
#fastest ⇒ Object
Returns the value of attribute fastest.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#percent_slower ⇒ Object
Returns the value of attribute percent_slower.
-
#run_time ⇒ Object
readonly
Returns the value of attribute run_time.
Class Method Summary collapse
Instance Method Summary collapse
- #fastest? ⇒ Boolean
-
#initialize(name, block) ⇒ Runnable
constructor
A new instance of Runnable.
- #run ⇒ Object
- #summary ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(name, block) ⇒ Runnable
Returns a new instance of Runnable.
16 17 18 19 |
# File 'lib/bench_press/runnable.rb', line 16 def initialize(name, block) @name = name @code_block = block end |
Instance Attribute Details
#code_block ⇒ Object (readonly)
Returns the value of attribute code_block.
3 4 5 |
# File 'lib/bench_press/runnable.rb', line 3 def code_block @code_block end |
#fastest ⇒ Object
Returns the value of attribute fastest.
4 5 6 |
# File 'lib/bench_press/runnable.rb', line 4 def fastest @fastest end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/bench_press/runnable.rb', line 3 def name @name end |
#percent_slower ⇒ Object
Returns the value of attribute percent_slower.
4 5 6 |
# File 'lib/bench_press/runnable.rb', line 4 def percent_slower @percent_slower end |
#run_time ⇒ Object (readonly)
Returns the value of attribute run_time.
3 4 5 |
# File 'lib/bench_press/runnable.rb', line 3 def run_time @run_time end |
Class Method Details
.repetitions ⇒ Object
7 8 9 |
# File 'lib/bench_press/runnable.rb', line 7 def repetitions @repetitions ||= 1000 end |
.repetitions=(times) ⇒ Object
11 12 13 |
# File 'lib/bench_press/runnable.rb', line 11 def repetitions=(times) @repetitions = times end |
Instance Method Details
#fastest? ⇒ Boolean
21 22 23 |
# File 'lib/bench_press/runnable.rb', line 21 def fastest? fastest == true end |
#run ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/bench_press/runnable.rb', line 25 def run r,w = IO.pipe fork do run_it time = Benchmark.realtime do run_it end w.write time w.close_write exit! end Process.waitall w.close_write @run_time = r.read.to_f end |
#summary ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/bench_press/runnable.rb', line 41 def summary if fastest? "Fastest" else "#{percent_slower}% Slower" end end |
#to_hash ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/bench_press/runnable.rb', line 49 def to_hash { :name => name, :run_time => run_time, :summary => summary, :fastest => fastest } end |