Class: Benchmark
- Inherits:
-
Object
- Object
- Benchmark
- Defined in:
- lib/benchmark_color.rb
Instance Attribute Summary collapse
-
#block_hash ⇒ Object
readonly
Returns the value of attribute block_hash.
-
#loser ⇒ Object
Returns the value of attribute loser.
-
#option ⇒ Object
Returns the value of attribute option.
-
#winner ⇒ Object
Returns the value of attribute winner.
Instance Method Summary collapse
- #compare ⇒ Object
-
#initialize(args = {}) ⇒ Benchmark
constructor
A new instance of Benchmark.
- #instructions ⇒ Object
- #measure(label = "") ⇒ Object
Methods included from Report
arrow, format, output, seperator, small_arrow
Methods included from Abacus
Constructor Details
#initialize(args = {}) ⇒ Benchmark
Returns a new instance of Benchmark.
71 72 73 74 75 76 |
# File 'lib/benchmark_color.rb', line 71 def initialize args={} @winner = args.fetch(:winner, :green) @loser = args.fetch(:loser, :red) @option = args.fetch(:option, :light_blue) @block_hash ||= {} end |
Instance Attribute Details
#block_hash ⇒ Object (readonly)
Returns the value of attribute block_hash.
65 66 67 |
# File 'lib/benchmark_color.rb', line 65 def block_hash @block_hash end |
#loser ⇒ Object
Returns the value of attribute loser.
66 67 68 |
# File 'lib/benchmark_color.rb', line 66 def loser @loser end |
#option ⇒ Object
Returns the value of attribute option.
66 67 68 |
# File 'lib/benchmark_color.rb', line 66 def option @option end |
#winner ⇒ Object
Returns the value of attribute winner.
66 67 68 |
# File 'lib/benchmark_color.rb', line 66 def winner @winner end |
Instance Method Details
#compare ⇒ Object
89 90 91 |
# File 'lib/benchmark_color.rb', line 89 def compare Report.output @block_hash, winner, loser, option end |
#instructions ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/benchmark_color.rb', line 93 def instructions %{You must supply a block of code like this: b = Benchmark.new b.measure("some-label:") { n.times do; x = 1 + 3; end} b.compare #to get your results Or this: n = 1000 b = Benchmark.new b.measure("some-label:") do n.times do x = 1 + 3 end end b.compare #to get your results} end |
#measure(label = "") ⇒ Object
78 79 80 81 82 83 84 85 86 87 |
# File 'lib/benchmark_color.rb', line 78 def measure label = "" if block_given? block = Abacus.block_time {yield} @block_hash[label] = block true else puts instructions false end end |