-
Notifications
You must be signed in to change notification settings - Fork 382
/
read_write.rb
52 lines (44 loc) · 1.44 KB
/
read_write.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
50
51
52
# The purpose of this is to check finding, initializing,
# and creating objects (typecasting times/dates and booleans).
require 'pp'
require 'benchmark'
require 'rubygems'
# to test with slow version just do this:
# gem 'mongo_mapper', '0.6.10'
# and comment out this:
$:.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
require 'mongo_mapper'
MongoMapper.database = 'testing'
class Foo
include MongoMapper::Document
key :approved, Boolean
key :count, Integer
key :approved_at, Time
key :expire_on, Date
timestamps!
end
Foo.collection.drop
Benchmark.bm(5) do |x|
ids = []
x.report("write") do
1000.times { |i| ids << Foo.create(:count => 0, :approved => true, :approved_at => Time.now, :expire_on => Date.today).id }
end
x.report("read ") do
ids.each { |id| Foo.first(:id => id) }
end
end
# I was get something like this on my puny macbook air:
# user system total real
# write 4.810000 0.090000 4.900000 ( 5.039949)
# read 2.730000 0.070000 2.800000 ( 2.990749)
#
#
# After these commits:
#
# * http://github.com/jnunemaker/mongomapper/commit/e5091fa140d5fae2721017b53027092233694ee5
# * http://github.com/jnunemaker/mongomapper/commit/c22bbde4fa1cfbc310d79cb0e50203310ffb03d1
#
# I'm now getting something like this:
# user system total real
# write 1.660000 0.050000 1.710000 ( 1.752676)
# read 1.060000 0.050000 1.110000 ( 1.263429)