@@ -34,81 +34,83 @@ private def create_entry
34
34
Benchmark ::IPS ::Entry .new(" label" , - > { 1 + 1 })
35
35
end
36
36
37
- describe Benchmark ::IPS ::Entry , " #set_cycles" do
38
- it " sets the number of cycles needed to make 100ms" do
39
- e = create_entry
40
- e.set_cycles(2 .seconds, 100 )
41
- e.cycles.should eq(5 )
42
-
43
- e.set_cycles(100 .milliseconds, 1 )
44
- e.cycles.should eq(1 )
45
- end
46
-
47
- it " sets the cycles to 1 no matter what" do
48
- e = create_entry
49
- e.set_cycles(2 .seconds, 1 )
50
- e.cycles.should eq(1 )
51
- end
37
+ private def h_mean (mean )
38
+ create_entry.tap { |e | e.mean = mean }.human_mean
52
39
end
53
40
54
- describe Benchmark :: IPS :: Entry , " #calculate_stats " do
55
- it " correctly calculates basic stats " do
56
- e = create_entry
57
- e.calculate_stats([ 2 , 4 , 4 , 4 , 5 , 5 , 7 , 9 ])
41
+ private def h_ips ( seconds )
42
+ mean = 1.0 / seconds
43
+ create_entry.tap { | e | e.mean = mean }.human_iteration_time
44
+ end
58
45
59
- e.size.should eq(8 )
60
- e.mean.should eq(5.0 )
61
- e.variance.should eq(4.0 )
62
- e.stddev.should eq(2.0 )
46
+ describe Benchmark ::IPS ::Entry do
47
+ describe " #set_cycles" do
48
+ it " sets the number of cycles needed to make 100ms" do
49
+ e = create_entry
50
+ e.set_cycles(2 .seconds, 100 )
51
+ e.cycles.should eq(5 )
52
+
53
+ e.set_cycles(100 .milliseconds, 1 )
54
+ e.cycles.should eq(1 )
55
+ end
56
+
57
+ it " sets the cycles to 1 no matter what" do
58
+ e = create_entry
59
+ e.set_cycles(2 .seconds, 1 )
60
+ e.cycles.should eq(1 )
61
+ end
63
62
end
64
- end
65
63
66
- private def h_mean (mean )
67
- create_entry.tap { |e | e.mean = mean }.human_mean
68
- end
64
+ describe " #calculate_stats" do
65
+ it " correctly calculates basic stats" do
66
+ e = create_entry
67
+ e.calculate_stats([2 , 4 , 4 , 4 , 5 , 5 , 7 , 9 ])
69
68
70
- describe Benchmark ::IPS ::Entry , " #human_mean" do
71
- it { h_mean(0.01234567890123 ).should eq(" 12.35m" ) }
72
- it { h_mean(0.12345678901234 ).should eq(" 123.46m" ) }
69
+ e.size.should eq(8 )
70
+ e.mean.should eq(5.0 )
71
+ e.variance.should eq(4.0 )
72
+ e.stddev.should eq(2.0 )
73
+ end
74
+ end
73
75
74
- it { h_mean( 1.23456789012345 ).should eq( " 1.23 " ) }
75
- it { h_mean(12.3456789012345 ).should eq(" 12.35 " ) }
76
- it { h_mean(123.456789012345 ).should eq(" 123.46 " ) }
76
+ describe " #human_mean " do
77
+ it { h_mean(0.01234567890123 ).should eq(" 12.35m " ) }
78
+ it { h_mean(0.12345678901234 ).should eq(" 123.46m " ) }
77
79
78
- it { h_mean(1234.56789012345 ).should eq(" 1.23k " ) }
79
- it { h_mean(12345.6789012345 ).should eq(" 12.35k " ) }
80
- it { h_mean(123456.789012345 ).should eq(" 123.46k " ) }
80
+ it { h_mean(1.23456789012345 ).should eq(" 1.23 " ) }
81
+ it { h_mean(12.3456789012345 ).should eq(" 12.35 " ) }
82
+ it { h_mean(123.456789012345 ).should eq(" 123.46 " ) }
81
83
82
- it { h_mean(1234567.89012345 ).should eq(" 1.23M " ) }
83
- it { h_mean(12345678.9012345 ).should eq(" 12.35M " ) }
84
- it { h_mean(123456789.012345 ).should eq(" 123.46M " ) }
84
+ it { h_mean(1234.56789012345 ).should eq(" 1.23k " ) }
85
+ it { h_mean(12345.6789012345 ).should eq(" 12.35k " ) }
86
+ it { h_mean(123456.789012345 ).should eq(" 123.46k " ) }
85
87
86
- it { h_mean(1234567890.12345 ).should eq(" 1.23G" ) }
87
- it { h_mean(12345678901.2345 ).should eq(" 12.35G" ) }
88
- it { h_mean(123456789012.345 ).should eq(" 123.46G" ) }
89
- end
88
+ it { h_mean(1234567.89012345 ).should eq(" 1.23M" ) }
89
+ it { h_mean(12345678.9012345 ).should eq(" 12.35M" ) }
90
+ it { h_mean(123456789.012345 ).should eq(" 123.46M" ) }
90
91
91
- private def h_ips ( seconds )
92
- mean = 1.0 / seconds
93
- create_entry.tap { | e | e.mean = mean }.human_iteration_time
94
- end
92
+ it { h_mean( 1234567890.12345 ).should eq( " 1.23G " ) }
93
+ it { h_mean( 12345678901.2345 ).should eq( " 12.35G " ) }
94
+ it { h_mean( 123456789012.345 ).should eq( " 123.46G " ) }
95
+ end
95
96
96
- describe Benchmark :: IPS :: Entry , " #human_iteration_time" do
97
- it { h_ips(1234.567 _890_123).should eq(" 1,234.57s " ) }
98
- it { h_ips(123.456 _789_012_3).should eq(" 123.46s " ) }
99
- it { h_ips(12.345 _678_901_23).should eq(" 12.35s " ) }
100
- it { h_ips(1.234 _567_890_123).should eq(" 1.23s " ) }
97
+ describe " #human_iteration_time" do
98
+ it { h_ips(1234.567 _890_123).should eq(" 1,234.57s " ) }
99
+ it { h_ips(123.456 _789_012_3).should eq(" 123.46s " ) }
100
+ it { h_ips(12.345 _678_901_23).should eq(" 12.35s " ) }
101
+ it { h_ips(1.234 _567_890_123).should eq(" 1.23s " ) }
101
102
102
- it { h_ips(0.123 _456_789_012).should eq(" 123.46ms" ) }
103
- it { h_ips(0.012 _345_678_901).should eq(" 12.35ms" ) }
104
- it { h_ips(0.001 _234_567_890).should eq(" 1.23ms" ) }
103
+ it { h_ips(0.123 _456_789_012).should eq(" 123.46ms" ) }
104
+ it { h_ips(0.012 _345_678_901).should eq(" 12.35ms" ) }
105
+ it { h_ips(0.001 _234_567_890).should eq(" 1.23ms" ) }
105
106
106
- it { h_ips(0.000 _123_456_789).should eq(" 123.46µs" ) }
107
- it { h_ips(0.000 _012_345_678).should eq(" 12.35µs" ) }
108
- it { h_ips(0.000 _001_234_567).should eq(" 1.23µs" ) }
107
+ it { h_ips(0.000 _123_456_789).should eq(" 123.46µs" ) }
108
+ it { h_ips(0.000 _012_345_678).should eq(" 12.35µs" ) }
109
+ it { h_ips(0.000 _001_234_567).should eq(" 1.23µs" ) }
109
110
110
- it { h_ips(0.000 _000_123_456).should eq(" 123.46ns" ) }
111
- it { h_ips(0.000 _000_012_345).should eq(" 12.34ns" ) }
112
- it { h_ips(0.000 _000_001_234).should eq(" 1.23ns" ) }
113
- it { h_ips(0.000 _000_000_123).should eq(" 0.12ns" ) }
111
+ it { h_ips(0.000 _000_123_456).should eq(" 123.46ns" ) }
112
+ it { h_ips(0.000 _000_012_345).should eq(" 12.34ns" ) }
113
+ it { h_ips(0.000 _000_001_234).should eq(" 1.23ns" ) }
114
+ it { h_ips(0.000 _000_000_123).should eq(" 0.12ns" ) }
115
+ end
114
116
end
0 commit comments