rroonga 1.3.0 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1,6 +1,6 @@
1
1
  # -*- coding: utf-8; mode: ruby -*-
2
2
  #
3
- # Copyright (C) 2009-2011 Kouhei Sutou <kou@clear-code.com>
3
+ # Copyright (C) 2009-2012 Kouhei Sutou <kou@clear-code.com>
4
4
  #
5
5
  # This library is free software; you can redistribute it and/or
6
6
  # modify it under the terms of the GNU Lesser General Public
@@ -168,7 +168,38 @@ relative_binary_dir = File.join("vendor", "local")
168
168
  vendor_dir = File.join(base_dir, relative_vendor_dir)
169
169
  binary_dir = File.join(base_dir, relative_binary_dir)
170
170
 
171
- groonga_win32_i386_p = ENV["GROONGA32"] == "yes"
171
+ groonga_win32_i386_p = ENV["GROONGA64"] != "yes"
172
+
173
+ namespace :win32 do
174
+ namespace :groonga do
175
+ task :download do
176
+ require "open-uri"
177
+ require "rroonga-build"
178
+ groonga_version = RroongaBuild::RequiredGroongaVersion::VERSION.join(".")
179
+ base_name = "groonga-#{groonga_version}-"
180
+ if groonga_win32_i386_p
181
+ base_name << "x86"
182
+ else
183
+ base_name << "x64"
184
+ end
185
+ base_name << ".zip"
186
+ base_url = "http://packages.groonga.org/windows/groonga/"
187
+ Dir.chdir(base_dir) do
188
+ unless File.exist?(base_name)
189
+ open("#{base_url}#{base_name}", "rb") do |zip|
190
+ File.open(base_name, "wb") do |output|
191
+ output.print(zip.read)
192
+ end
193
+ end
194
+ end
195
+ sh("unzip", base_name)
196
+ rm_rf(relative_binary_dir)
197
+ mkdir_p(File.dirname(relative_binary_dir))
198
+ mv(File.basename(base_name, ".*"), relative_binary_dir)
199
+ end
200
+ end
201
+ end
202
+ end
172
203
 
173
204
  Rake::ExtensionTask.new("groonga", spec) do |ext|
174
205
  if groonga_win32_i386_p
data/benchmark/common.rb CHANGED
@@ -35,7 +35,7 @@ def report(index=0)
35
35
  end
36
36
 
37
37
  if index.zero?
38
- puts(" " * (width - 1) + Benchmark::Tms::CAPTION.rstrip + "memory".rjust(14))
38
+ puts(" " * (width - 1) + Benchmark::Tms::CAPTION.rstrip + "memory".rjust(11))
39
39
  end
40
40
  # GC.disable
41
41
  before = memory_usage
@@ -44,6 +44,6 @@ def report(index=0)
44
44
  GC.start
45
45
  size = memory_usage - before
46
46
 
47
- formatted_size = "%10.3f" % size
47
+ formatted_size = "%7.3f" % size
48
48
  puts "#{label.ljust(width)} #{result.to_s.strip} #{formatted_size}MB"
49
49
  end
@@ -3,32 +3,31 @@
3
3
  # This benchmark is based on Tokyo Cabinet's benchmark at
4
4
  # http://alpha.mixi.co.jp/blog/?p=791
5
5
  #
6
- # On my environment at 2009/07/14:
7
- # % for x in {0..9}; do ruby benchmark/read-write-many-small-items.rb $x; done
8
- # user system total real memory
9
- # Hash 0.850000 0.170000 1.020000 ( 1.050703) 46.957MB
10
- # groonga: Hash: memory 1.080000 0.180000 1.260000 ( 1.251981) 30.152MB
11
- # groonga: Trie: memory 1.300000 0.120000 1.420000 ( 1.429549) 22.199MB
12
- # groonga: Hash: file 1.070000 0.190000 1.260000 ( 1.276910) 30.156MB
13
- # groonga: Trie: file 1.280000 0.150000 1.430000 ( 1.423066) 22.203MB
14
- # Localmemcache: file 1.320000 0.150000 1.470000 ( 1.497013) 45.984MB
15
- # TC: Hash: memory 0.940000 0.250000 1.190000 ( 1.248141) 48.758MB
16
- # TC: Tree: memory 0.890000 0.140000 1.030000 ( 1.067693) 37.270MB
17
- # TC: Hash: file 1.740000 2.390000 4.130000 ( 4.141555) 8.848MB
18
- # TC: Tree: file 1.290000 0.180000 1.470000 ( 1.476853) 12.805MB
6
+ # On my environment at 2012/01/25:
7
+ # % for x in {0..8}; do ruby1.9.1 benchmark/read-write-many-small-items.rb $x; done
8
+ # user system total real memory
9
+ # Hash 0.410000 0.000000 0.410000 ( 0.412228) 44.895MB
10
+ # groonga: Hash 0.910000 0.030000 0.940000 ( 0.938278) 38.863MB
11
+ # groonga: PatriciaTrie 1.050000 0.020000 1.070000 ( 1.076237) 34.832MB
12
+ # groonga: DoubleArrayTrie 1.050000 0.040000 1.090000 ( 1.083912) 34.852MB
13
+ # Localmemcache: file 0.610000 0.040000 0.650000 ( 0.641539) 61.441MB
14
+ # TC: Hash: memory 0.470000 0.010000 0.480000 ( 0.477577) 55.910MB
15
+ # TC: Tree: memory 0.430000 0.010000 0.440000 ( 0.441939) 44.484MB
16
+ # TC: Hash: file 0.980000 0.990000 1.970000 ( 1.971581) 17.684MB
17
+ # TC: Tree: file 0.650000 0.030000 0.680000 ( 0.683004) 19.801MB
19
18
  #
20
- # CPU: Intel(R) Core(TM)2 Duo 2.33GHz
21
- # Memory: 2GB
22
- # Ruby: Debian GNU/Linux sid at 2009/07/14:
23
- # ruby 1.8.7 (2009-06-12 patchlevel 174) [x86_64-linux]
24
- # groonga: HEAD at 2009/07/14: fdaf58df5dd0195c10624eabee3e3f522f4af3f9
25
- # Ruby/Groonga: trunk at 2009/07/14: r479
26
- # Localmemcache: HEAD at 2009/07/14: 3121629016344dfd10f7533ca8ec68a0006cca21
27
- # Tokyo Cabinet: 1.4.29
28
- # Tokyo Cabinet Ruby: 1.27
19
+ # CPU: Intel(R) Core(TM) i7 CPU 860 @ 2.80GHz stepping 05
20
+ # Memory: 8GB
21
+ # Ruby: Debian GNU/Linux sid at 2012/01/25:
22
+ # ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-linux]
23
+ # groonga: HEAD at 2012/01/25: 07dce043cc8cfbbecbcdc43bf7c6d5c2d085237a
24
+ # rroonga: master at 2012/01/25: 29099bff93377733d81dc2398c3403e1293301dc
25
+ # Localmemcache: 0.4.4
26
+ # Tokyo Cabinet: 1.4.37
27
+ # Tokyo Cabinet Ruby: 1.31
29
28
  #
30
29
  # NOTE:
31
- # * groonga, Localmemcache and Tokyo Cabinet are built with "-O3" option.
30
+ # * groonga, Localmemcache and Tokyo Cabinet are built with "-O2" option.
32
31
  # * Ruby bindings of them are built with "-O2" option.
33
32
 
34
33
  require File.join(File.dirname(__FILE__), "common.rb")
@@ -40,44 +39,54 @@ n.times do |i|
40
39
  values << "%08d" % i
41
40
  end
42
41
 
42
+ ruby_hash = {}
43
43
  item("Hash") do
44
- @hash = {}
45
44
  values.each do |value|
46
- @hash[value] = value
47
- @hash[value]
45
+ ruby_hash[value] = value
46
+ ruby_hash[value]
48
47
  end
49
48
  end
50
49
 
51
50
  begin
52
51
  base_dir = File.expand_path(File.join(File.dirname(__FILE__), ".."))
53
- $LOAD_PATH.unshift(File.join(base_dir, "ext"))
52
+ $LOAD_PATH.unshift(File.join(base_dir, "ext", "groonga"))
54
53
  $LOAD_PATH.unshift(File.join(base_dir, "lib"))
55
54
 
56
55
  require 'groonga'
57
56
  tmp_dir = "/tmp/groonga"
58
57
  FileUtils.rm_rf(tmp_dir)
59
58
  FileUtils.mkdir(tmp_dir)
59
+ Groonga::Context.default.encoding = :none
60
60
  @database = Groonga::Database.create(:path => "#{tmp_dir}/db")
61
+ column_name = "value"
61
62
 
62
- item("groonga: Hash: file") do
63
- @hash = Groonga::Hash.create(:name => "Hash",
64
- :key_type => "ShortText")
65
- column_name = "value"
66
- @column = @hash.define_column(column_name, "ShortText")
63
+ groonga_hash = Groonga::Hash.create(:name => "Hash",
64
+ :key_type => "ShortText")
65
+ groonga_hash.define_column(column_name, "ShortText")
66
+ item("groonga: Hash") do
67
67
  values.each do |value|
68
- @hash.set_column_value(value, column_name, value)
69
- @hash.column_value(value, column_name)
68
+ groonga_hash.set_column_value(value, column_name, value)
69
+ groonga_hash.column_value(value, column_name)
70
70
  end
71
71
  end
72
72
 
73
- item("groonga: Trie: file") do
74
- @trie = Groonga::PatriciaTrie.create(:name => "PatriciaTrie",
75
- :key_type => "ShortText")
76
- column_name = "value"
77
- @column = @trie.define_column(column_name, "ShortText")
73
+ patricia_trie = Groonga::PatriciaTrie.create(:name => "PatriciaTrie",
74
+ :key_type => "ShortText")
75
+ patricia_trie.define_column(column_name, "ShortText")
76
+ item("groonga: PatriciaTrie") do
78
77
  values.each do |value|
79
- @trie.set_column_value(value, column_name, value)
80
- @trie.column_value(value, column_name)
78
+ patricia_trie.set_column_value(value, column_name, value)
79
+ patricia_trie.column_value(value, column_name)
80
+ end
81
+ end
82
+
83
+ double_array_trie = Groonga::DoubleArrayTrie.create(:name => "DoubleArrayTrie",
84
+ :key_type => "ShortText")
85
+ double_array_trie.define_column(column_name, "ShortText")
86
+ item("groonga: DoubleArrayTrie") do
87
+ values.each do |value|
88
+ patricia_trie.set_column_value(value, column_name, value)
89
+ patricia_trie.column_value(value, column_name)
81
90
  end
82
91
  end
83
92
  rescue LoadError
@@ -86,13 +95,13 @@ end
86
95
  begin
87
96
  require 'localmemcache'
88
97
 
98
+ LocalMemCache.drop(:namespace => "read-write-many-small-items",
99
+ :force => true)
100
+ mem_cache = LocalMemCache.new(:namespace => "read-write-many-small-items")
89
101
  item("Localmemcache: file") do
90
- LocalMemCache.drop(:namespace => "read-write-many-small-items",
91
- :force => true)
92
- @db = LocalMemCache.new(:namespace => "read-write-many-small-items")
93
102
  values.each do |value|
94
- @db[value] = value
95
- @db[value]
103
+ mem_cache[value] = value
104
+ mem_cache[value]
96
105
  end
97
106
  end
98
107
  rescue LoadError
@@ -101,41 +110,41 @@ end
101
110
  begin
102
111
  require 'tokyocabinet'
103
112
 
113
+ tc_hash_memory = TokyoCabinet::ADB::new
114
+ tc_hash_memory.open("*#bnum=#{n}#mode=wct#xmsiz=0")
104
115
  item("TC: Hash: memory") do
105
- @db = TokyoCabinet::ADB::new
106
- @db.open("*#bnum=#{n}#mode=wct#xmsiz=0")
107
116
  values.each do |value|
108
- @db.put(value, value)
109
- @db.get(value)
117
+ tc_hash_memory.put(value, value)
118
+ tc_hash_memory.get(value)
110
119
  end
111
120
  end
112
121
 
122
+ tc_tree_memory = TokyoCabinet::ADB::new
123
+ tc_tree_memory.open("+#bnum=#{n}#mode=wct#xmsiz=0")
113
124
  item("TC: Tree: memory") do
114
- @db = TokyoCabinet::ADB::new
115
- @db.open("+#bnum=#{n}#mode=wct#xmsiz=0")
116
125
  values.each do |value|
117
- @db.put(value, value)
118
- @db.get(value)
126
+ tc_tree_memory.put(value, value)
127
+ tc_tree_memory.get(value)
119
128
  end
120
129
  end
121
130
 
122
131
  hash_file = Tempfile.new(["tc-hash", ".tch"])
132
+ tc_hash_file = TokyoCabinet::ADB::new
133
+ tc_hash_file.open("#{hash_file.path}#bnum=#{n}#mode=wct#xmsiz=0")
123
134
  item("TC: Hash: file") do
124
- @db = TokyoCabinet::ADB::new
125
- @db.open("#{hash_file.path}#bnum=#{n}#mode=wct#xmsiz=0")
126
135
  values.each do |value|
127
- @db.put(value, value)
128
- @db.get(value)
136
+ tc_hash_file.put(value, value)
137
+ tc_hash_file.get(value)
129
138
  end
130
139
  end
131
140
 
132
141
  tree_file = Tempfile.new(["tc-tree", ".tcb"])
142
+ tc_tree_file = TokyoCabinet::ADB::new
143
+ tc_tree_file.open("#{tree_file.path}#bnum=#{n}#mode=wct#xmsiz=0")
133
144
  item("TC: Tree: file") do
134
- @db = TokyoCabinet::ADB::new
135
- @db.open("#{tree_file.path}#bnum=#{n}#mode=wct#xmsiz=0")
136
145
  values.each do |value|
137
- @db.put(value, value)
138
- @db.get(value)
146
+ tc_tree_file.put(value, value)
147
+ tc_tree_file.get(value)
139
148
  end
140
149
  end
141
150
  rescue LoadError
@@ -3,32 +3,31 @@
3
3
  # This benchmark is based on Tokyo Cabinet's benchmark at
4
4
  # http://alpha.mixi.co.jp/blog/?p=791
5
5
  #
6
- # On my environment at 2009/07/14:
7
- # % for x in {0..9}; do ruby benchmark/write-many-small-items.rb $x; done
8
- # user system total real memory
9
- # Hash 0.650000 0.130000 0.780000 ( 0.799843) 46.957MB
10
- # groonga: Hash: memory 0.650000 0.130000 0.780000 ( 0.781058) 23.477MB
11
- # groonga: Trie: memory 0.690000 0.180000 0.870000 ( 0.862132) 15.516MB
12
- # groonga: Hash: file 0.660000 0.120000 0.780000 ( 0.780952) 23.480MB
13
- # groonga: Trie: file 0.660000 0.190000 0.850000 ( 0.867515) 15.520MB
14
- # Localmemcache: file 0.900000 0.150000 1.050000 ( 1.052692) 39.312MB
15
- # TC: Hash: memory 0.480000 0.150000 0.630000 ( 0.636297) 42.062MB
16
- # TC: Tree: memory 0.440000 0.150000 0.590000 ( 0.593117) 30.570MB
17
- # TC: Hash: file 1.000000 1.820000 2.820000 ( 2.989515) 2.160MB
18
- # TC: Tree: file 0.720000 0.130000 0.850000 ( 0.877557) 6.102MB
6
+ # On my environment at 2012/01/25:
7
+ # % for x in {0..8}; do ruby1.9.1 benchmark/write-many-small-items.rb $x; done
8
+ # user system total real memory
9
+ # Hash 0.320000 0.030000 0.350000 ( 0.345441) 44.910MB
10
+ # groonga: Hash 0.490000 0.020000 0.510000 ( 0.512336) 23.305MB
11
+ # groonga: PatriciaTrie 0.560000 0.010000 0.570000 ( 0.572077) 19.242MB
12
+ # groonga: DoubleArrayTrie 0.700000 0.020000 0.720000 ( 0.730448) 39.789MB
13
+ # Localmemcache: file 0.510000 0.040000 0.550000 ( 0.549663) 45.898MB
14
+ # TC: Hash: memory 0.270000 0.020000 0.290000 ( 0.292051) 40.148MB
15
+ # TC: Tree: memory 0.220000 0.010000 0.230000 ( 0.229233) 28.727MB
16
+ # TC: Hash: file 0.610000 0.630000 1.240000 ( 1.247094) 2.129MB
17
+ # TC: Tree: file 0.340000 0.040000 0.380000 ( 0.377910) 4.000MB
19
18
  #
20
- # CPU: Intel(R) Core(TM)2 Duo 2.33GHz
21
- # Memory: 2GB
22
- # Ruby: Debian GNU/Linux sid at 2009/07/14:
23
- # ruby 1.8.7 (2009-06-12 patchlevel 174) [x86_64-linux]
24
- # groonga: HEAD at 2009/07/14: fdaf58df5dd0195c10624eabee3e3f522f4af3f9
25
- # Ruby/Groonga: trunk at 2009/07/14: r479
26
- # Localmemcache: HEAD at 2009/07/14: 3121629016344dfd10f7533ca8ec68a0006cca21
27
- # Tokyo Cabinet: 1.4.29
28
- # Tokyo Cabinet Ruby: 1.27
19
+ # CPU: Intel(R) Core(TM) i7 CPU 860 @ 2.80GHz stepping 05
20
+ # Memory: 8GB
21
+ # Ruby: Debian GNU/Linux sid at 2012/01/25:
22
+ # ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-linux]
23
+ # groonga: HEAD at 2012/01/25: 07dce043cc8cfbbecbcdc43bf7c6d5c2d085237a
24
+ # rroonga: master at 2012/01/25: 29099bff93377733d81dc2398c3403e1293301dc
25
+ # Localmemcache: 0.4.4
26
+ # Tokyo Cabinet: 1.4.37
27
+ # Tokyo Cabinet Ruby: 1.31
29
28
  #
30
29
  # NOTE:
31
- # * groonga, Localmemcache and Tokyo Cabinet are built with "-O3" option.
30
+ # * groonga, Localmemcache and Tokyo Cabinet are built with "-O2" option.
32
31
  # * Ruby bindings of them are built with "-O2" option.
33
32
 
34
33
  require File.join(File.dirname(__FILE__), "common.rb")
@@ -40,41 +39,50 @@ n.times do |i|
40
39
  values << "%08d" % i
41
40
  end
42
41
 
42
+ ruby_hash = {}
43
43
  item("Hash") do
44
- @hash = {}
45
44
  values.each do |value|
46
- @hash[value] = value
45
+ ruby_hash[value] = value
47
46
  end
48
47
  end
49
48
 
50
49
  begin
51
50
  base_dir = File.expand_path(File.join(File.dirname(__FILE__), ".."))
52
- $LOAD_PATH.unshift(File.join(base_dir, "ext"))
51
+ $LOAD_PATH.unshift(File.join(base_dir, "ext", "groonga"))
53
52
  $LOAD_PATH.unshift(File.join(base_dir, "lib"))
54
53
 
55
54
  require 'groonga'
56
55
  tmp_dir = "/tmp/groonga"
57
56
  FileUtils.rm_rf(tmp_dir)
58
57
  FileUtils.mkdir(tmp_dir)
58
+ Groonga::Context.default.encoding = :none
59
59
  @database = Groonga::Database.create(:path => "#{tmp_dir}/db")
60
+ column_name = "value"
60
61
 
61
- item("groonga: Hash: file") do
62
- @hash = Groonga::Hash.create(:name => "Hash",
63
- :key_type => "ShortText")
64
- column_name = "value"
65
- @column = @hash.define_column(column_name, "ShortText")
62
+ groonga_hash = Groonga::Hash.create(:name => "Hash",
63
+ :key_type => "ShortText")
64
+ groonga_hash.define_column(column_name, "ShortText")
65
+ item("groonga: Hash") do
66
66
  values.each do |value|
67
- @hash.set_column_value(value, column_name, value)
67
+ groonga_hash.set_column_value(value, column_name, value)
68
68
  end
69
69
  end
70
70
 
71
- item("groonga: Trie: file") do
72
- @trie = Groonga::PatriciaTrie.create(:name => "PatriciaTrie",
73
- :key_type => "ShortText")
74
- column_name = "value"
75
- @column = @trie.define_column(column_name, "ShortText")
71
+ patricia_trie = Groonga::PatriciaTrie.create(:name => "PatriciaTrie",
72
+ :key_type => "ShortText")
73
+ patricia_trie.define_column(column_name, "ShortText")
74
+ item("groonga: PatriciaTrie") do
76
75
  values.each do |value|
77
- @trie.set_column_value(value, column_name, value)
76
+ patricia_trie.set_column_value(value, column_name, value)
77
+ end
78
+ end
79
+
80
+ double_array_trie = Groonga::DoubleArrayTrie.create(:name => "DoubleArrayTrie",
81
+ :key_type => "ShortText")
82
+ double_array_trie.define_column(column_name, "ShortText")
83
+ item("groonga: DoubleArrayTrie") do
84
+ values.each do |value|
85
+ double_array_trie.set_column_value(value, column_name, value)
78
86
  end
79
87
  end
80
88
  rescue LoadError
@@ -83,11 +91,11 @@ end
83
91
  begin
84
92
  require 'localmemcache'
85
93
 
94
+ LocalMemCache.drop(:namespace => "write-many-small-items", :force => true)
95
+ mem_cache = LocalMemCache.new(:namespace => "write-many-small-items")
86
96
  item("Localmemcache: file") do
87
- LocalMemCache.drop(:namespace => "write-many-small-items", :force => true)
88
- @db = LocalMemCache.new(:namespace => "write-many-small-items")
89
97
  values.each do |value|
90
- @db[value] = value
98
+ mem_cache[value] = value
91
99
  end
92
100
  end
93
101
  rescue LoadError
@@ -96,37 +104,37 @@ end
96
104
  begin
97
105
  require 'tokyocabinet'
98
106
 
107
+ tc_hash_memory = TokyoCabinet::ADB::new
108
+ tc_hash_memory.open("*#bnum=#{n}#mode=wct#xmsiz=0")
99
109
  item("TC: Hash: memory") do
100
- @db = TokyoCabinet::ADB::new
101
- @db.open("*#bnum=#{n}#mode=wct#xmsiz=0")
102
110
  values.each do |value|
103
- @db.put(value, value)
111
+ tc_hash_memory.put(value, value)
104
112
  end
105
113
  end
106
114
 
115
+ tc_tree_memory = TokyoCabinet::ADB::new
116
+ tc_tree_memory.open("+#bnum=#{n}#mode=wct#xmsiz=0")
107
117
  item("TC: Tree: memory") do
108
- @db = TokyoCabinet::ADB::new
109
- @db.open("+#bnum=#{n}#mode=wct#xmsiz=0")
110
118
  values.each do |value|
111
- @db.put(value, value)
119
+ tc_tree_memory.put(value, value)
112
120
  end
113
121
  end
114
122
 
115
123
  hash_file = Tempfile.new(["tc-hash", ".tch"])
124
+ tc_hash_file = TokyoCabinet::ADB::new
125
+ tc_hash_file.open("#{hash_file.path}#bnum=#{n}#mode=wct#xmsiz=0")
116
126
  item("TC: Hash: file") do
117
- @db = TokyoCabinet::ADB::new
118
- @db.open("#{hash_file.path}#bnum=#{n}#mode=wct#xmsiz=0")
119
127
  values.each do |value|
120
- @db.put(value, value)
128
+ tc_hash_file.put(value, value)
121
129
  end
122
130
  end
123
131
 
124
132
  tree_file = Tempfile.new(["tc-tree", ".tcb"])
133
+ tc_tree_file = TokyoCabinet::ADB::new
134
+ tc_tree_file.open("#{tree_file.path}#bnum=#{n}#mode=wct#xmsiz=0")
125
135
  item("TC: Tree: file") do
126
- @db = TokyoCabinet::ADB::new
127
- @db.open("#{tree_file.path}#bnum=#{n}#mode=wct#xmsiz=0")
128
136
  values.each do |value|
129
- @db.put(value, value)
137
+ tc_tree_file.put(value, value)
130
138
  end
131
139
  end
132
140
  rescue LoadError