groonga 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. data/NEWS.ja.rdoc +11 -0
  2. data/NEWS.rdoc +11 -0
  3. data/README.ja.rdoc +4 -3
  4. data/README.rdoc +4 -3
  5. data/Rakefile +1 -1
  6. data/TUTORIAL.ja.rdoc +168 -44
  7. data/benchmark/common.rb +49 -0
  8. data/benchmark/read-write-small-many-items.rb +156 -0
  9. data/benchmark/write-small-many-items.rb +145 -0
  10. data/example/bookmark.rb +68 -20
  11. data/ext/rb-grn-array-cursor.c +8 -0
  12. data/ext/rb-grn-array.c +40 -11
  13. data/ext/rb-grn-column.c +38 -209
  14. data/ext/rb-grn-context.c +203 -56
  15. data/ext/rb-grn-database.c +119 -5
  16. data/ext/rb-grn-encoding-support.c +64 -0
  17. data/ext/rb-grn-encoding.c +58 -1
  18. data/ext/rb-grn-fix-size-column.c +220 -0
  19. data/ext/rb-grn-hash-cursor.c +8 -0
  20. data/ext/rb-grn-hash.c +244 -2
  21. data/ext/rb-grn-index-column.c +474 -0
  22. data/ext/rb-grn-object.c +143 -265
  23. data/ext/rb-grn-patricia-trie.c +148 -2
  24. data/ext/rb-grn-query.c +5 -3
  25. data/ext/rb-grn-record.c +3 -2
  26. data/ext/rb-grn-snippet.c +5 -3
  27. data/ext/rb-grn-table-cursor-key-support.c +3 -3
  28. data/ext/rb-grn-table-cursor.c +106 -112
  29. data/ext/rb-grn-table-key-support.c +220 -118
  30. data/ext/rb-grn-table.c +336 -80
  31. data/ext/rb-grn-type.c +5 -4
  32. data/ext/rb-grn-utils.c +62 -63
  33. data/ext/rb-grn.h +215 -14
  34. data/ext/rb-groonga.c +7 -16
  35. data/extconf.rb +3 -1
  36. data/html/favicon.ico +0 -0
  37. data/html/favicon.xcf +0 -0
  38. data/html/index.html +1 -7
  39. data/lib/groonga/record.rb +6 -1
  40. data/test/groonga-test-utils.rb +1 -0
  41. data/test/test-array.rb +81 -0
  42. data/test/test-column.rb +22 -12
  43. data/test/test-context.rb +1 -29
  44. data/test/test-database.rb +30 -0
  45. data/test/test-hash.rb +194 -0
  46. data/test/test-index-column.rb +57 -0
  47. data/test/test-patricia-trie.rb +82 -0
  48. data/test/test-record.rb +10 -10
  49. data/test/test-table.rb +37 -130
  50. data/test/test-type.rb +4 -3
  51. metadata +15 -4
  52. data/benchmark/small-many-items.rb +0 -175
data/NEWS.ja.rdoc CHANGED
@@ -1,5 +1,16 @@
1
1
  = お知らせ
2
2
 
3
+ == 0.0.2: 2009-06-04
4
+
5
+ * groonga 0.0.9対応 [mori]
6
+ * 性能向上: キー、値、ドメイン、レンジをキャッシュ
7
+ * API改良
8
+ * ドキュメントの追加
9
+ * Ruby 1.9対応
10
+ * バグ修正:
11
+ ** インストール処理の修正 [Tasuku SUENAGA]
12
+ ** メモリリーク修正
13
+
3
14
  == 0.0.1: 2009-04-30
4
15
 
5
16
  * 最初のリリース!
data/NEWS.rdoc CHANGED
@@ -1,5 +1,16 @@
1
1
  = NEWS
2
2
 
3
+ == 0.0.2: 2009-06-04
4
+
5
+ * Supported groonga 0.0.9 [mori]
6
+ * Improved preformance: cache key, value, domain and range
7
+ * Improved API
8
+ * Added documents
9
+ * Supported Ruby 1.9
10
+ * Bug fixes:
11
+ ** Fixed install process [Tasuku SUENAGA]
12
+ ** Fixed memory leaks
13
+
3
14
  == 0.0.1: 2009-04-30
4
15
 
5
16
  * Initial release!
data/README.ja.rdoc CHANGED
@@ -20,7 +20,7 @@ groongaに関する情報は以下を参照して下さい。
20
20
 
21
21
  == 作者
22
22
 
23
- Kouhei Sutou <kou@clear-code.com>
23
+ Kouhei Sutou: <tt><kou@clear-code.com></tt>
24
24
 
25
25
  == ライセンス
26
26
 
@@ -32,7 +32,7 @@ pkg-config.rbはrcairoに付属しているもので、これはRubyライセ
32
32
  == 依存ソフトウェア
33
33
 
34
34
  * Ruby >= 1.8 (1.9.1対応)
35
- * groonga >= 0.0.4
35
+ * groonga >= 0.0.8
36
36
 
37
37
  == インストール
38
38
 
@@ -50,4 +50,5 @@ http://lists.sourceforge.jp/mailman/listinfo/groonga-dev
50
50
 
51
51
  == 感謝
52
52
 
53
- * ...
53
+ * 森さん: 最新groonga対応パッチをくれました。
54
+ * グニャラくん: バグレポートしてくれました。
data/README.rdoc CHANGED
@@ -20,7 +20,7 @@ See the following URL about groonga.
20
20
 
21
21
  == Author
22
22
 
23
- Kouhei Sutou <kou@clear-code.com>
23
+ Kouhei Sutou: <tt><kou@clear-code.com></tt>
24
24
 
25
25
  == License
26
26
 
@@ -33,7 +33,7 @@ license/GPL for details.
33
33
  == Dependencies
34
34
 
35
35
  * Ruby >= 1.8 (including 1.9.1)
36
- * groonga >= 0.0.4
36
+ * groonga >= 0.0.8
37
37
 
38
38
  == Install
39
39
 
@@ -51,4 +51,5 @@ http://rubyforge.org/mailman/listinfo/groonga-users-en
51
51
 
52
52
  == Thanks
53
53
 
54
- * ...
54
+ * mori: sent patches to support the latest groonga.
55
+ * Tasuku SUENAGA: sent bug reports.
data/Rakefile CHANGED
@@ -27,7 +27,7 @@ require 'hoe'
27
27
 
28
28
  ENV["NODOT"] = "yes"
29
29
 
30
- Hoe::SUPPORTED_TEST_FRAMEWORKS[:testunit2] = "test/run-test.rb"
30
+ Hoe::Test::SUPPORTED_TEST_FRAMEWORKS[:testunit2] = "test/run-test.rb"
31
31
 
32
32
  base_dir = File.join(File.dirname(__FILE__))
33
33
  truncate_base_dir = Proc.new do |x|
data/TUTORIAL.ja.rdoc CHANGED
@@ -1,7 +1,7 @@
1
1
  = チュートリアル
2
2
 
3
3
  このページでは簡単なアプリケーションの作成を通して
4
- Ruby/groongaの新しいSennaの操作方法を紹介します。
4
+ Ruby/groongaの操作方法を紹介します。
5
5
 
6
6
  == インストール
7
7
 
@@ -50,14 +50,14 @@ groongaには以下の3種類のテーブルがあります。
50
50
  配列。主キーの存在しないテーブルです。レコードはIDによって
51
51
  識別します。
52
52
 
53
- ここではハッシュテーブルを利用して、+<items>+という名前のテー
53
+ ここではハッシュテーブルを利用して、<tt><items></tt>という名前のテー
54
54
  ブルを作成します。
55
55
 
56
56
  >> items = Groonga::Hash.create(:name => "<items>", :persistent => true)
57
57
  => #<Groonga::Hash id: <18>, name: <<items>>, path: </tmp/bookmark.db.0000012>, domain: <nil>, range: <nil>, encoding: <:utf8>, size: <0>>
58
58
 
59
59
 
60
- これで+<items>+という名前のテーブルが作成できました。
60
+ これで<tt><items></tt>という名前のテーブルが作成できました。
61
61
 
62
62
  テーブルはRubyのHashのように扱えます。
63
63
 
@@ -72,9 +72,9 @@ groongaには以下の3種類のテーブルがあります。
72
72
  items>テーブルにレコードを追加します。
73
73
 
74
74
  >> items.add("http://ja.wikipedia.org/wiki/Ruby")
75
- => #<Groonga::Record:0x7f0ece6aeaf8 @table=#<Groonga::Hash id: <18>, name: <<items>>, path: </tmp/bookmark.db.0000012>, domain: <nil>, range: <nil>, encoding: <:utf8>, size: <1>>, @id=1>
75
+ => #<Groonga::Record ...>
76
76
  >> items.add("http://www.ruby-lang.org/")
77
- => #<Groonga::Record:0x7f0ece6a9fa8 @table=#<Groonga::Hash id: <18>, name: <<items>>, path: </tmp/bookmark.db.0000012>, domain: <nil>, range: <nil>, encoding: <:utf8>, size: <2>>, @id=2>
77
+ => #<Groonga::Record ...>
78
78
 
79
79
  件数を確認すると確かに2件増えています。
80
80
 
@@ -83,21 +83,21 @@ items>テーブルにレコードを追加します。
83
83
 
84
84
  主キーを指定してレコードを取り出す時には以下のようにします。
85
85
 
86
- >> items["http://ja.wikipedia.org/wiki/Ruby"]
87
- => #<Groonga::Record:0x7f0ece699ab8 @table=#<Groonga::Hash id: <18>, name: <<items>>, path: </tmp/bookmark.db.0000012>, domain: <nil>, range: <nil>, encoding: <:utf8>, size: <2>>, @id=1>
86
+ >> items.find("http://ja.wikipedia.org/wiki/Ruby")
87
+ => #<Groonga::Record ...>
88
88
 
89
89
  == 全文検索を行う
90
90
 
91
91
  各itemのタイトル文字列を登録して、全文検索できるようにしてみ
92
92
  ましょう。
93
93
 
94
- まず+<items>+テーブルに+title+という名前のカラムを追加します。
94
+ まず<tt><items></tt>テーブルに+title+という名前のカラムを追加します。
95
95
 
96
- >> title_colum = items.define_column("title", "<text>")
97
- => #<Groonga::VarSizeColumn id: <19>, name: <<items>.title>, path: (temporary), domain: <#<Groonga::Hash id: <18>, name: <<items>>, path: </tmp/bookmark.db.0000012>, domain: <nil>, range: <nil>, encoding: <:utf8>, size: <2>>>, range: <#<Groonga::Type id: <7>, name: <<text>>, path: (temporary), domain: <nil>, range: <65536>>>>
96
+ >> title_colum = items.define_column("title", "<text>", :persistent => true)
97
+ => #<Groonga::VarSizeColumn ...>
98
98
 
99
99
  2番目の引数は、追加するカラムのデータ型を示しています。
100
- +<int>+、+<text>+、+<longtext>+等の型が基本型として用意されて
100
+ <tt><int></tt>、<tt><text></tt>、<tt><longtext></tt>等の型が基本型として用意されて
101
101
  います。
102
102
 
103
103
  全文検索するためには、文字列を分解して得られる各単語を格納す
@@ -106,42 +106,51 @@ items>テーブルにレコードを追加します。
106
106
 
107
107
  >> terms = Groonga::Hash.create(:name => "<terms>",
108
108
  :key_type => "<shorttext>",
109
- :persistent => true)
110
- => #<Groonga::Hash id: <21>, name: <<terms>>, path: </tmp/bookmark.db.0000015>, domain: <#<Groonga::Type id: <6>, name: <<shorttext>>, path: (temporary), domain: <nil>, range: <4096>>>, range: <nil>, encoding: <:utf8>, size: <0>>
111
-
112
- +<items>+テーブルの+title+カラムに対するインデックスを定義し
113
- ます。
114
-
115
- >> title_index_column = terms.define_column("item_title", items,
116
- :type => "index",
117
- :with_position => true)
118
- => #<Groonga::IndexColumn id: <22>, name: <<terms>.item_title>, path: (temporary), domain: <#<Groonga::Hash id: <21>, name: <<terms>>, path: </tmp/bookmark.db.0000015>, domain: <#<Groonga::Type id: <6>, name: <<shorttext>>, path: (temporary), domain: <nil>, range: <4096>>>, range: <nil>, encoding: <:utf8>, size: <0>>>, range: <#<Groonga::Hash id: <18>, name: <<items>>, path: </tmp/bookmark.db.0000012>, domain: <nil>, range: <nil>, encoding: <:utf8>, size: <2>>>>
119
-
120
- インデックス用カラムに、検索対象の+<items>+テーブルの+title+
121
- カラムを設定します。
122
-
123
- >> title_index_column.source = title_column
124
- => #<Groonga::VarSizeColumn id: <19>, name: <<items>.title>, path: (temporary), domain: <#<Groonga::Hash id: <18>, name: <<items>>, path: </tmp/bookmark.db.0000012>, domain: <nil>, range: <nil>, encoding: <:utf8>, size: <2>>>, range: <#<Groonga::Type id: <7>, name: <<text>>, path: (temporary), domain: <nil>, range: <65536>>>>
125
-
126
- 少し違和感を感じるかも知れませんが、+<items>+テーブルのカラムに
127
- 対するインデックスは、 +<terms>+テーブルのカラムとして定義しま
128
- す。
129
-
130
- +<items>+にレコードが登録されると、その中に含まれる単語に該当
131
- するレコードが+<terms>+に自動的に追加されるようになります。
132
-
133
- +<terms>+は、文書に含まれる語彙に相当する、やや特殊なテーブル
134
- だと言えます。しかし、他のテーブルと同様に語彙テーブルには自
135
- 由にカラムを追加し、単語毎の様々な属性を管理することができま
136
- す。これはある種の検索処理を行う際には非常に便利に機能します。
109
+ :persistent => true,
110
+ :default_tokenizer => "<token:bigram>")
111
+ => #<Groonga::Hash ...>
112
+
113
+ ここでは、トークナイザとして<tt>:default_tokenzier =>
114
+ "<token:bigram>"</tt> を指定しています。トークナイザとは文字
115
+ 列を単語に分解するオブジェクトのことです。デフォルトではトー
116
+ クナイザは指定されていません。全文検索を利用するためにはトー
117
+ クナイザを指定する必要があるので、ここではN-gramの一種である
118
+ バイグラムを指定しています。
119
+
120
+ N-gramを利用した全文検索では、分解したN文字とその出現位置を利
121
+ 用して全文検索を行います。N-gramのNは文字列を何文字毎に分解す
122
+ るかの文字数になります。groongaは1文字で分解するユニグラム、
123
+ 2文字のバイグラム、3文字のトリグラムをサポートしています。
124
+
125
+ 単語格納用テーブルの準備ができたので、<tt><items></tt>テーブ
126
+ ルの+title+カラムに対するインデックスを定義します。
127
+
128
+ >> terms.define_index_column("item_title", items,
129
+ :persistent => true,
130
+ :source => "<items>.title")
131
+ => #<Groonga::IndexColumn ...>
132
+
133
+ 少し違和感を感じるかも知れませんが、<tt><items></tt>テーブル
134
+ のカラムに対するインデックスは、<tt><terms></tt>テーブルのカ
135
+ ラムとして定義します。
136
+
137
+ <tt><items></tt>にレコードが登録されると、その中に含まれる単
138
+ 語に該当するレコードが<tt><terms></tt>に自動的に追加されるよ
139
+ うになります。
140
+
141
+ <tt><terms></tt>は、文書に含まれる語彙に相当する、やや特殊な
142
+ テーブルだと言えます。しかし、他のテーブルと同様に語彙テーブ
143
+ ルには自由にカラムを追加し、単語毎の様々な属性を管理すること
144
+ ができます。これはある種の検索処理を行う際には非常に便利に機
145
+ 能します。
137
146
 
138
147
  これでテーブルの定義は完了です。
139
148
 
140
149
  先ほど登録した各レコードの+title+カラムに値をセットします。
141
150
 
142
- >> items["http://ja.wikipedia.org/wiki/Ruby"]["title"] = "Ruby"
151
+ >> items.find("http://ja.wikipedia.org/wiki/Ruby")["title"] = "Ruby"
143
152
  => "Ruby"
144
- >> items["http://www.ruby-lang.org/"]["title"] = "オブジェクトスクリプト言語Ruby"
153
+ >> items.find("http://www.ruby-lang.org/")["title"] = "オブジェクトスクリプト言語Ruby"
145
154
  "オブジェクトスクリプト言語Ruby"
146
155
 
147
156
  以下のようにして検索することができます。
@@ -150,11 +159,126 @@ items>テーブルにレコードを追加します。
150
159
  ["http://ja.wikipedia.org/wiki/Ruby", "http://www.ruby-lang.org/"]
151
160
 
152
161
  検索結果はGroonga::Hashで返されます。ハッシュのキーに見つかっ
153
- た+<items>+のレコードが入っています。上の例ではrecord.keyで
154
- +<items>+のレコードを取得して、さらにそのキーを指定して
155
- record.key.key)で+<items>+のキーを返しています。
162
+ た<tt><items></tt>のレコードが入っています。上の例では
163
+ +record.key+で<tt><items></tt>のレコードを取得して、さらにそ
164
+ のキーを指定して(+record.key.key+)で<tt><items></tt>のキー
165
+ を返しています。
156
166
 
157
167
 
158
168
  == マルチユーザ向けのブックマークアプリケーション
159
169
 
170
+ ここまでで作った単機能のアプリケーションをもう少し拡張して、
171
+ 複数のユーザが、それぞれにコメントを記入できるブックマークア
172
+ プリケーションにしてみましょう。
173
+
174
+ まず、ユーザ情報とコメント情報を格納するテーブルを追加して、
175
+ 下図のようなテーブル構成にします。
176
+
177
+ http://qwik.jp/senna/senna2.files/rect4605.png
178
+
179
+ まず、<tt><users></tt>テーブルを追加します。
180
+
181
+ >> users = Groonga::Hash.create(:name => "<users>",
182
+ :key_type => "<shorttext>")
183
+ => #<Groonga::Hash ...>
184
+ >> users.define_column("name", "<text>")
185
+ => #<Groonga::VarSizeColumn ...>
186
+
187
+
188
+ 次に、<tt><comments></tt>テーブルを追加します。
189
+
190
+ >> comments = Groonga::Hash.create(:name => "<comments>",
191
+ :key_type => "<shorttext>")
192
+ => #<Groonga::Hash ...>
193
+ >> comments.define_column("item", items)
194
+ => #<Groonga::FixSizeColumn ..>
195
+ >> comments.define_column("author", users)
196
+ => #<Groonga::FixSizeColumn ..>
197
+ >> comments.define_column("content", "<text>")
198
+ => #<Groonga::VarSizeColumn ..>
199
+ >> comments.define_column("issued", "<time>")
200
+ => #<Groonga::FixSizeColumn ..>
201
+
202
+ <tt><comments></tt>テーブルの+content+カラムを全文検索できる
203
+ ようにインデックスを定義します。
204
+
205
+ >> terms.define_index_column("comment_content", comments,
206
+ :source => "<comments>.content")
207
+ => #<Groonga::IndexColumn ...>
208
+
209
+ これでテーブルが定義できました。
210
+
211
+ 続いてユーザを何人か追加します。
212
+
213
+ >> users.add("moritan", :name => "モリタン")
214
+ => #<Groonga::Record ...>
215
+ >> users.add("taporobo", :name => "タポロボ")
216
+ => #<Groonga::Record ...>
217
+
218
+ 次に、実際にユーザがブックマークを貼る時の処理を実行してみま
219
+ しょう。
220
+
221
+ ユーザ+moritan+が、はてなダイアリーのとあるページをブックマーク
222
+ したと想定します。
223
+
224
+ まず対象のページが<tt><items></tt>テーブルに登録済かどうか調
225
+ べます。
226
+
227
+ >> items.find("http://d.hatena.ne.jp/brazil/20050829/1125321936")
228
+ => nil
229
+
230
+ 未登録なのでまず当該ページを<tt><items></tt>に登録します。
231
+
232
+ >> items.add("http://d.hatena.ne.jp/brazil/20050829/1125321936",
233
+ :title => "[翻訳]JavaScript: 世界で最も誤解されたプログラミング言語")
234
+ => #<Groonga::Record ...>
235
+
236
+ 次に、登録したitemを+item+カラムの値に指定して
237
+ <tt><comments></tt>にレコードを登録します。
238
+
239
+ >> comments.add(:item => "http://d.hatena.ne.jp/brazil/20050829/1125321936",
240
+ :author => "moritan",
241
+ :content => "JavaScript LISP",
242
+ :issued => 1187430026)
243
+ => #<Groonga::Record ...>
244
+
245
+ == メソッド化
246
+
247
+ 上記の一連の手続きをメソッドにまとめてみます。
248
+
249
+ >> @items = items
250
+ >> @comments = comments
251
+ >> def add_bookmark(url, title, author, content, issued)
252
+ >> item = @items.find(url) || @items.add(url, :title => title)
253
+ >> @comments.add(:item => item,
254
+ >> :author => author,
255
+ >> :content => content,
256
+ >> :issued => issued)
257
+ >> end
258
+
259
+ +itmes+と+comments+をインスタンス変数に代入しているのはメソッ
260
+ ド内からでも見えるようにするためです。
261
+
262
+ +add_bookmark+は以下のような手順を実行しています。
263
+
264
+ * <tt><items></tt>テーブルに該当ページのレコードがあるかどうか調べる。
265
+ * レコードがなければ追加する。
266
+ * <tt><comments></tt>テーブルにレコードを登録する。
267
+
268
+ 作成したメソッドを呼び出していくつかブックマークを登録してみ
269
+ ましょう。
270
+
271
+ >> add_bookmark("http://practical-scheme.net/docs/cont-j.html",
272
+ "なんでも継続", "moritan", "継続 LISP Scheme", 1187568692)
273
+ => #<Groonga::Record ...>
274
+ >> add_bookmark("http://d.hatena.ne.jp/higepon/20070815/1187192864",
275
+ "末尾再帰", "taporobo", "末尾再帰 Scheme LISP", 1187568793)
276
+ => #<Groonga::Record ...>
277
+ >> add_bookmark("http://practical-scheme.net/docs/cont-j.html",
278
+ "なんでも継続", "taporobo", "トランポリン LISP continuation",
279
+ 1187568692)
280
+ => #<Groonga::Record ...>
281
+
282
+ == 全文検索その2
283
+
160
284
  つづく。。。
@@ -0,0 +1,49 @@
1
+ require 'benchmark'
2
+ require 'tempfile'
3
+
4
+ def memory_usage()
5
+ status = `cat /proc/#{$$}/status`
6
+ lines = status.split("\n")
7
+ lines.each do |line|
8
+ if line =~ /^VmRSS:/
9
+ line.gsub!(/.*:\s*(\d+).*/, '\1')
10
+ return line.to_i / 1024.0
11
+ end
12
+ end
13
+ return -1;
14
+ end
15
+
16
+ @items = []
17
+
18
+ def item(label, &block)
19
+ @items << [label, block]
20
+ end
21
+
22
+ def report(index=0)
23
+ width = @items.collect do |label, _|
24
+ label.length
25
+ end.max
26
+
27
+ label, block = @items[index]
28
+ if label.nil?
29
+ puts "unavailable report ID: #{index}"
30
+ puts "available IDs:"
31
+ @items.each_with_index do |(label, block), i|
32
+ puts "#{i}: #{label}"
33
+ end
34
+ exit 1
35
+ end
36
+
37
+ if index.zero?
38
+ puts(" " * (width - 1) + Benchmark::Tms::CAPTION.rstrip + "memory".rjust(14))
39
+ end
40
+ # GC.disable
41
+ before = memory_usage
42
+ result = Benchmark.measure(&block)
43
+ # GC.enable
44
+ GC.start
45
+ size = memory_usage - before
46
+
47
+ formatted_size = "%10.3f" % size
48
+ puts "#{label.ljust(width)} #{result.to_s.strip} #{formatted_size}MB"
49
+ end
@@ -0,0 +1,156 @@
1
+ #!/usr/bin/ruby
2
+
3
+ # This benchmark is based on Tokyo Cabinet's benchmark at
4
+ # http://alpha.mixi.co.jp/blog/?p=791
5
+ #
6
+ # On my environment at 2009/05/16:
7
+ # % for x in {0..9}; do ruby benchmark/read-write-small-many-items.rb $x; done
8
+ # user system total real memory
9
+ # Hash 1.440000 0.120000 1.560000 ( 2.018838) 47.230MB
10
+ # groonga: Hash: memory 1.780000 0.170000 1.950000 ( 2.331934) 30.582MB
11
+ # groonga: Trie: memory 2.220000 0.150000 2.370000 ( 2.788049) 22.594MB
12
+ # groonga: Hash: file 1.810000 0.170000 1.980000 ( 2.389940) 30.590MB
13
+ # groonga: Trie: file 2.170000 0.150000 2.320000 ( 2.862775) 22.594MB
14
+ # Localmemcache: file 1.710000 0.240000 1.950000 ( 2.311414) 46.410MB
15
+ # TC: Hash: memory 1.540000 0.180000 1.720000 ( 2.048307) 49.180MB
16
+ # TC: Tree: memory 1.410000 0.160000 1.570000 ( 1.891273) 37.691MB
17
+ # TC: Hash: file 2.420000 2.950000 5.370000 ( 7.122531) 9.258MB
18
+ # TC: Tree: file 2.080000 0.220000 2.300000 ( 2.876335) 13.234MB
19
+ #
20
+ # Ruby: Debian GNU/Linux sid at 2009/05/16:
21
+ # ruby 1.8.7 (2008-08-11 patchlevel 72) [x86_64-linux]
22
+ # groonga: HEAD at 2009/05/16: ed49074fbc217b97c0b0b8d675f2417f9490c87e
23
+ # Ruby/Groonga: trunk at 2009/05/16: r321
24
+ # Localmemcache: HEAD at 2009/05/16: 6f8cfbd3a103c2be8d54834a65deb096d7cda34f
25
+ # Tokyo Cabinet: 1.4.20
26
+ # Tokyo Cabinet Ruby: 1.23
27
+ #
28
+ # NOTE: All C source codes are built with "-g -O0"
29
+ # option. They will be more faster with "-O2" option.
30
+
31
+ require File.join(File.dirname(__FILE__), "common.rb")
32
+
33
+ n = 500000
34
+
35
+ values = []
36
+ n.times do |i|
37
+ values << "%08d" % i
38
+ end
39
+
40
+ item("Hash") do
41
+ @hash = {}
42
+ values.each do |value|
43
+ @hash[value] = value
44
+ @hash[value]
45
+ end
46
+ end
47
+
48
+ begin
49
+ base_dir = File.expand_path(File.join(File.dirname(__FILE__), ".."))
50
+ $LOAD_PATH.unshift(File.join(base_dir, "ext"))
51
+ $LOAD_PATH.unshift(File.join(base_dir, "lib"))
52
+
53
+ require 'groonga'
54
+ @database = Groonga::Database.create
55
+
56
+ item("groonga: Hash: memory") do
57
+ @hash = Groonga::Hash.create(:key_type => "<shorttext>",
58
+ :value_size => 8)
59
+ values.each do |value|
60
+ @hash[value] = value
61
+ @hash[value]
62
+ end
63
+ end
64
+
65
+ item("groonga: Trie: memory") do
66
+ @hash = Groonga::PatriciaTrie.create(:key_type => "<shorttext>",
67
+ :value_size => 8)
68
+ values.each do |value|
69
+ @hash[value] = value
70
+ @hash[value]
71
+ end
72
+ end
73
+
74
+ @hash_file = Tempfile.new("groonga-hash")
75
+ item("groonga: Hash: file") do
76
+ @hash = Groonga::Hash.create(:key_type => "<shorttext>",
77
+ :value_size => 8,
78
+ :path => @hash_file.path)
79
+ values.each do |value|
80
+ @hash[value] = value
81
+ @hash[value]
82
+ end
83
+ end
84
+
85
+ trie_file = Tempfile.new("groonga-trie")
86
+ item("groonga: Trie: file") do
87
+ @hash = Groonga::PatriciaTrie.create(:key_type => "<shorttext>",
88
+ :value_size => 8,
89
+ :path => trie_file.path)
90
+ values.each do |value|
91
+ @hash[value] = value
92
+ @hash[value]
93
+ end
94
+ end
95
+ rescue LoadError
96
+ end
97
+
98
+ begin
99
+ require 'localmemcache'
100
+
101
+ item("Localmemcache: file") do
102
+ LocalMemCache.drop(:namespace => "read-write-small-many-items",
103
+ :force => true)
104
+ @db = LocalMemCache.new(:namespace => "read-write-small-many-items")
105
+ values.each do |value|
106
+ @db[value] = value
107
+ @db[value]
108
+ end
109
+ end
110
+ rescue LoadError
111
+ end
112
+
113
+ begin
114
+ require 'tokyocabinet'
115
+
116
+ item("TC: Hash: memory") do
117
+ @db = TokyoCabinet::ADB::new
118
+ @db.open("*#bnum=#{n}#mode=wct#xmsiz=0")
119
+ values.each do |value|
120
+ @db.put(value, value)
121
+ @db.get(value)
122
+ end
123
+ end
124
+
125
+ item("TC: Tree: memory") do
126
+ @db = TokyoCabinet::ADB::new
127
+ @db.open("+#bnum=#{n}#mode=wct#xmsiz=0")
128
+ values.each do |value|
129
+ @db.put(value, value)
130
+ @db.get(value)
131
+ end
132
+ end
133
+
134
+ hash_file = Tempfile.new(["tc-hash", ".tch"])
135
+ item("TC: Hash: file") do
136
+ @db = TokyoCabinet::ADB::new
137
+ @db.open("#{hash_file.path}#bnum=#{n}#mode=wct#xmsiz=0")
138
+ values.each do |value|
139
+ @db.put(value, value)
140
+ @db.get(value)
141
+ end
142
+ end
143
+
144
+ tree_file = Tempfile.new(["tc-tree", ".tcb"])
145
+ item("TC: Tree: file") do
146
+ @db = TokyoCabinet::ADB::new
147
+ @db.open("#{tree_file.path}#bnum=#{n}#mode=wct#xmsiz=0")
148
+ values.each do |value|
149
+ @db.put(value, value)
150
+ @db.get(value)
151
+ end
152
+ end
153
+ rescue LoadError
154
+ end
155
+
156
+ report(Integer(ARGV[0] || 0))