rbtree-jruby 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -14,7 +14,7 @@ GEM
14
14
  json (1.7.5)
15
15
  json (1.7.5-java)
16
16
  multi_json (1.3.6)
17
- rake (0.9.2.2)
17
+ rake (10.0.2)
18
18
  rcov (0.9.11)
19
19
  rcov (0.9.11-java)
20
20
  rdoc (3.12)
data/README.md CHANGED
@@ -55,6 +55,17 @@ duplications of keys but MultiRBTree does.
55
55
  end # => ["a", 20] ["a", 40] ["c", 10]
56
56
  ```
57
57
 
58
+ Benchmarks
59
+ -----------
60
+
61
+ Benchmark takes from headius' [redblack](https://github.com/headius/redblack) project.
62
+ Compared to [rbtree-pure](https://github.com/pwnall/rbtree-pure) and
63
+ [rbtree c extension](https://github.com/skade/rbtree).
64
+ ![benchmark result](https://raw.github.com/isaiah/rbtree-jruby/master/benchmark/result.png)
65
+
66
+ It's interesting to see jruby with invokedynamic almost gets C extension speed, and
67
+ jruby native extension is even faster than it's counterpart.
68
+ For more details, checkout [benchmark directory](https://github.com/isaiah/rbtree-jruby/tree/master/benchmark).
58
69
 
59
70
  Requirement
60
71
  -----------
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
data/benchmark/bm.rb ADDED
@@ -0,0 +1,26 @@
1
+ #$:.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
2
+ require 'rbtree'
3
+ require "benchmark"
4
+
5
+ def rbt_bm
6
+ n = 1_000
7
+ a1 = []; n.times { a1 << rand(999_999) }
8
+ a2 = []; n.times { a2 << rand(999_999) }
9
+
10
+ start = Time.now
11
+ tree = RBTree.new
12
+ a1.each {|e| tree[e] = e }
13
+ a2.each {|e| tree[e] }
14
+ n.times do
15
+ tree.delete_if{|k, v| v == rand(999_999)}
16
+ end
17
+
18
+ return Time.now - start
19
+ end
20
+
21
+ N = (ARGV[0] || 5).to_i
22
+
23
+ N.times do
24
+ puts rbt_bm.to_f
25
+ puts "GC.count = #{GC.count}" if GC.respond_to?(:count)
26
+ end
data/benchmark/bm1.rb ADDED
@@ -0,0 +1,30 @@
1
+ #$:.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
2
+ require 'rbtree'
3
+ require "benchmark"
4
+
5
+ def rbt_bm
6
+ n = 100_000
7
+ a1 = []; n.times { a1 << rand(999_999) }
8
+ a2 = []; n.times { a2 << rand(999_999) }
9
+
10
+ start = Time.now
11
+
12
+ tree = RBTree.new
13
+
14
+ n.times {|i| tree[i] = i }
15
+ n.times {|i| tree.delete(i) }
16
+
17
+ tree = RBTree.new
18
+ a1.each {|e| tree[e] = e }
19
+ a2.each {|e| tree[e] }
20
+ tree.each {|key, value| value + 1 }
21
+ tree.reverse_each {|key, value| value + 1 }
22
+ return Time.now - start
23
+ end
24
+
25
+ N = (ARGV[0] || 5).to_i
26
+
27
+ N.times do
28
+ puts rbt_bm.to_f
29
+ #puts "GC.count = #{GC.count}" if GC.respond_to?(:count)
30
+ end
Binary file
@@ -0,0 +1,114 @@
1
+ $ ruby -v && ruby bm1.rb 20
2
+ ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-linux]
3
+ 4.194673558
4
+ 4.134828053
5
+ 4.206916244
6
+ 4.1981704
7
+ 4.239772576
8
+ 4.126600891
9
+ 4.197231759
10
+ 4.182520993
11
+ 4.264266545
12
+ 4.175277231
13
+ 4.281924272
14
+ 4.180804353
15
+ 4.288204194
16
+ 4.219386288
17
+ 4.288127756
18
+ 4.174234309
19
+ 4.289359396
20
+ 4.186658554
21
+ 4.281877193
22
+ 4.17202375
23
+
24
+ $ ruby -v && ruby --server bm1.rb 20
25
+ jruby 1.7.0 (1.9.3p203) 2012-10-22 ff1ebbe on Java HotSpot(TM) 64-Bit Server VM 1.7.0_09-b05 [linux-amd64]
26
+ 3.936
27
+ 1.743
28
+ 1.854
29
+ 1.697
30
+ 1.678
31
+ 1.759
32
+ 1.772
33
+ 1.719
34
+ 1.697
35
+ 1.681
36
+ 1.646
37
+ 1.755
38
+ 1.72
39
+ 1.669
40
+ 1.719
41
+ 1.647
42
+ 1.771
43
+ 1.714
44
+ 1.658
45
+ 1.706
46
+
47
+ $ ruby -v && ruby -Xcompile.invokedynamic=true bm1.rb 20
48
+ jruby 1.7.0 (1.9.3p203) 2012-10-22 ff1ebbe on Java HotSpot(TM) 64-Bit Server VM 1.7.0_09-b05 [linux-amd64]
49
+ 4.489
50
+ 2.282
51
+ 1.76
52
+ 0.984
53
+ 0.928
54
+ 1.123
55
+ 0.988
56
+ 0.998
57
+ 0.915
58
+ 0.973
59
+ 0.981
60
+ 0.955
61
+ 0.95
62
+ 0.946
63
+ 0.979
64
+ 0.964
65
+ 0.955
66
+ 1.151
67
+ 1.142
68
+ 1.092
69
+
70
+ $ ruby -v && ruby bm1.rb 20
71
+ ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-linux]
72
+ 0.719245967
73
+ 0.764002064
74
+ 0.721334569
75
+ 0.724404531
76
+ 0.759026423
77
+ 0.762418384
78
+ 0.862859985
79
+ 0.7481005
80
+ 0.733698733
81
+ 0.768279468
82
+ 0.740369856
83
+ 0.735618093
84
+ 0.752477701
85
+ 0.845850977
86
+ 0.742914898
87
+ 0.762281986
88
+ 0.816316566
89
+ 0.739624534
90
+ 0.79819584
91
+ 0.749143339
92
+
93
+ $ ruby -v && ruby --server bm1.rb 20
94
+ jruby 1.7.0 (1.9.3p203) 2012-10-22 ff1ebbe on Java HotSpot(TM) 64-Bit Server VM 1.7.0_09-b05 [linux-amd64]
95
+ 1.044
96
+ 0.37
97
+ 0.406
98
+ 0.349
99
+ 0.293
100
+ 0.332
101
+ 0.305
102
+ 0.424
103
+ 0.332
104
+ 0.314
105
+ 0.332
106
+ 0.335
107
+ 0.334
108
+ 0.347
109
+ 0.335
110
+ 0.304
111
+ 0.333
112
+ 0.302
113
+ 0.335
114
+ 0.315