-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmongo_index.rb
49 lines (38 loc) · 980 Bytes
/
mongo_index.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/common'
require 'mongo'
m = Mongo::Connection.new
m.drop_database('quotest2')
db = m.db("quotest2")
coll = db.collection("day")
Benchmark.bm do |x, logger|
symbols = Set.new
x.report("write:") do
i = 0
QuoteDay.each do |ohlc|
break if i == MAX_RECORDS
coll.insert(ohlc)
i += 1
symbols.add(ohlc["symbol"])
end
end
x.report("index:") do
coll.create_index([["symbol", Mongo::ASCENDING], ["date", Mongo::DESCENDING]])
end
x.report("q30:") do
symbols.each do |s|
results = coll.find("symbol" => s).sort(["date", "descending"]).limit(30).map do |r|
r
end
end
end
x.report("qall:") do
symbols.each do |s|
results = coll.find("symbol" => s).sort(["date", "descending"]).map do |r|
r
end
end
end
# db size: datasize + indexsize
logger << sprintf(",%d", db.stats["dataSize"] + db.stats["indexSize"])
end