File tree 5 files changed +35
-46
lines changed
5 files changed +35
-46
lines changed Original file line number Diff line number Diff line change 1
- # gem install benchmark_suite
2
- require 'benchmark/ips'
3
-
4
- require 'hamster/hash'
1
+ require "benchmark/ips"
2
+ require "hamster/hash"
5
3
6
4
Benchmark . ips do |b |
7
5
sml_hash = Hamster . hash ( 1 => 1 )
8
6
med_hash = Hamster . hash
9
- 1_000 . times { |i | med_hash = med_hash . put ( i , i ) }
7
+ 1_000 . times { |i | med_hash = med_hash . put ( i , i ) }
10
8
lrg_hash = Hamster . hash
11
- 1_000_000 . times { |i | lrg_hash = lrg_hash . put ( i , i ) }
12
-
9
+ 1_000_000 . times { |i | lrg_hash = lrg_hash . put ( i , i ) }
10
+
13
11
b . report "each small" do |n |
14
12
a = 0
15
13
x = 0
16
14
while a < n
17
- sml_hash . each { |y | x = y }
15
+ sml_hash . each { |y | x = y }
18
16
a += 1
19
17
end
20
18
end
21
-
19
+
22
20
b . report "each medium" do |n |
23
21
a = 0
24
22
x = 0
25
23
while a < n
26
- med_hash . each { |y | x = y }
24
+ med_hash . each { |y | x = y }
27
25
a += 1
28
26
end
29
27
end
30
-
28
+
31
29
b . report "each large" do |n |
32
30
a = 0
33
31
x = 0
34
32
while a < n
35
- lrg_hash . each { |y | x = y }
33
+ lrg_hash . each { |y | x = y }
36
34
a += 1
37
35
end
38
36
end
39
- end
37
+ end
Original file line number Diff line number Diff line change 1
- # gem install benchmark_suite
2
- require 'benchmark/ips'
1
+ require "benchmark/ips"
3
2
4
- require ' hamster/hash'
3
+ require " hamster/hash"
5
4
6
5
Benchmark . ips do |b |
7
6
sml_hash = Hamster . hash ( 1 => 1 )
8
7
med_hash = Hamster . hash
9
- 1_000 . times { |i | med_hash = med_hash . put ( i , i ) }
8
+ 1_000 . times { |i | med_hash = med_hash . put ( i , i ) }
10
9
lrg_hash = Hamster . hash
11
- 1_000_000 . times { |i | lrg_hash = lrg_hash . put ( i , i ) }
12
-
10
+ 1_000_000 . times { |i | lrg_hash = lrg_hash . put ( i , i ) }
11
+
13
12
b . report "get existing small" do |n |
14
13
a = 0
15
14
x = 0
18
17
a += 1
19
18
end
20
19
end
21
-
20
+
22
21
b . report "get existing medium" do |n |
23
22
a = 0
24
23
x = nil
27
26
a += 1
28
27
end
29
28
end
30
-
29
+
31
30
b . report "get existing large" do |n |
32
31
a = 0
33
32
x = nil
36
35
a += 1
37
36
end
38
37
end
39
-
38
+
40
39
b . report "get missing small" do |n |
41
40
a = 0
42
41
x = 0
45
44
a += 1
46
45
end
47
46
end
48
-
47
+
49
48
b . report "get existing medium" do |n |
50
49
a = 0
51
50
x = nil
54
53
a += 1
55
54
end
56
55
end
57
-
56
+
58
57
b . report "get existing large" do |n |
59
58
a = 0
60
59
x = nil
64
63
end
65
64
end
66
65
end
67
-
Original file line number Diff line number Diff line change 1
- # gem install benchmark_suite
2
- require 'benchmark/ips'
3
-
4
- require 'hamster/hash'
1
+ require "benchmark/ips"
2
+ require "hamster/hash"
5
3
6
4
Benchmark . ips do |b |
7
5
sml_hash = Hamster . hash ( 1 => 1 )
8
6
med_hash = Hamster . hash
9
- 1_000 . times { |i | med_hash = med_hash . put ( i , i ) }
7
+ 1_000 . times { |i | med_hash = med_hash . put ( i , i ) }
10
8
lrg_hash = Hamster . hash
11
- 1_000_000 . times { |i | lrg_hash = lrg_hash . put ( i , i ) }
9
+ 1_000_000 . times { |i | lrg_hash = lrg_hash . put ( i , i ) }
12
10
13
11
b . report "put value" do |n |
14
12
a = 0
18
16
a += 1
19
17
end
20
18
end
21
-
19
+
22
20
b . report "put value medium" do |n |
23
21
a = 0
24
22
med = med_hash
27
25
a += 1
28
26
end
29
27
end
30
-
28
+
31
29
b . report "put value large" do |n |
32
30
a = 0
33
31
lrg = lrg_hash
37
35
end
38
36
end
39
37
end
40
-
Original file line number Diff line number Diff line change 1
- # gem install benchmark_suite
2
- require 'benchmark/ips'
3
-
4
- require 'hamster/list'
1
+ require "benchmark/ips"
2
+ require "hamster/list"
5
3
6
4
Benchmark . ips do |b |
7
5
sml_list = Hamster . list ( 1 )
8
6
# med_list = Hamster.iterate(1, &:next).take(100)
9
7
# lrg_list = Hamster.iterate(1, &:next).take(10000)
10
8
med_list = Hamster . list
11
- 100 . times { |i | med_list = med_list . cons ( i ) }
9
+ 100 . times { |i | med_list = med_list . cons ( i ) }
12
10
lrg_list = Hamster . list
13
- 10000 . times { |i | lrg_list = lrg_list . cons ( i ) }
11
+ 10000 . times { |i | lrg_list = lrg_list . cons ( i ) }
14
12
15
13
b . report "at small" do |n |
16
14
a = 0
Original file line number Diff line number Diff line change 1
- # gem install benchmark_suite
2
- require 'benchmark/ips'
3
-
4
- require 'hamster/list'
1
+ require "benchmark/ips"
2
+ require "hamster/list"
5
3
6
4
Benchmark . ips do |b |
7
5
sml_list = Hamster . list ( 1 )
8
6
med_list = Hamster . list
9
- 100 . times { |i | med_list = med_list . cons ( i ) }
7
+ 100 . times { |i | med_list = med_list . cons ( i ) }
10
8
lrg_list = Hamster . list
11
- 10000 . times { |i | lrg_list = lrg_list . cons ( i ) }
9
+ 10000 . times { |i | lrg_list = lrg_list . cons ( i ) }
12
10
13
11
b . report "cons small" do |n |
14
12
a = 0
You can’t perform that action at this time.
0 commit comments