Module: BenchTest
- Extended by:
- BenchTest
- Includes:
- MiniTest::Assertions
- Included in:
- BenchTest
- Defined in:
- lib/bench_test.rb,
lib/bench_test/version.rb
Constant Summary collapse
- N_BYTES =
[42].pack('i').size
- N_BITS =
N_BYTES * 8
- FixnumMAX =
2 ** (N_BITS - 2) - 1
- FixnumMIN =
- 1
- VERSION =
"0.0.2"
Instance Method Summary collapse
-
#assert_comparison(operator1, comparison, operator2, type: 'real') ⇒ Object
BenchTest.assert_comparison operator1, comparison, operator2.
-
#range(min: FixnumMIN, max: FixnumMAX, type: 'real', name: '', &b) ⇒ Object
BenchTest.range min: 1.0e-10, max: 1.0e+3, name: ‘Load fixture’ do load(‘path/to/file’) end.
Instance Method Details
#assert_comparison(operator1, comparison, operator2, type: 'real') ⇒ Object
BenchTest.assert_comparison operator1, comparison, operator2
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/bench_test.rb', line 28 def assert_comparison(operator1, comparison, operator2, type: 'real') raise ArgumentError, 'assert_comparison(proc, symbol, *proc)' unless operator1.kind_of?(Proc) && comparison.kind_of?(Symbol) && operator2.kind_of?(Proc) bench_operator1 = Benchmark.measure { operator1.call }.send(type) bench_operator2 = Benchmark.measure { operator2.call }.send(type) msg = "Operator 1: #{bench_operator1} not #{comparison} operator 2 #{bench_operator2}" case comparison when :== assert bench_operator1 == bench_operator2, msg when :> assert bench_operator1 > bench_operator2, msg when :< assert bench_operator1 < bench_operator2, msg when :>= assert bench_operator1 >= bench_operator2, msg when :<= assert bench_operator1 <= bench_operator2, msg when '!='.to_sym assert bench_operator1 != bench_operator2, msg else end end |
#range(min: FixnumMIN, max: FixnumMAX, type: 'real', name: '', &b) ⇒ Object
BenchTest.range min: 1.0e-10, max: 1.0e+3, name: ‘Load fixture’ do
load('path/to/file')
end
19 20 21 22 23 24 |
# File 'lib/bench_test.rb', line 19 def range(min: FixnumMIN, max: FixnumMAX, type: 'real', name: '', &b) raise ArgumentError, 'Need block for test of range', caller unless block_given? time = Benchmark.measure { yield }.send(type) is_range = (min..max).include?(time) assert is_range, "Running block #{name} time #{time} not include in range #{min} < #{time} < #{max}".sub(/\s{2,3}/,' ') end |