class EJDBAdvancedTestUnit < Test::Unit::TestCase
RS = 100000
- QRS = 100000
+ QRS = 10000
def test_ejdbadv1_performance
assert_not_nil $jb
puts "Saved #{RS} objects, time: #{Time.now - st} s"
assert_equal(RS, $jb.find("pcoll1", {}, :onlycount => true))
+ puts "Checking saved..."
+ (recs).each { |rec|
+ assert_equal(1, $jb.find("pcoll1", rec, :onlycount => true))
+ }
+
puts "Quering..."
st = Time.now
(1..QRS).each {
- rec = recs.sample
- assert_equal(1, $jb.find("pcoll1", rec, :onlycount => true), "Strange record: #{rec}")
+ $jb.find("pcoll1", recs.sample, :onlycount => true)
}
+ secs = Time.now - st
+ puts "#{QRS} queries, time: #{secs} s, #{'%.6f' % (secs / QRS)} s per query"
+
+
+ puts "Setting index..."
+
+ st = Time.now
+ $jb.ensure_string_index("pcoll1", "rstring")
+ puts "Index built in #{Time.now - st} s"
+
+ puts "Quering again..."
+ st = Time.now
+ (1..QRS).each {
+ $jb.find("pcoll1", recs.sample, :onlycount => true)
+ }
secs = Time.now - st
- puts "#{QRS} queries, time: #{secs} s, #{secs / QRS} s per query"
+ puts "#{QRS} queries with rstring index, time: #{secs} s, #{'%.6f' % (secs / QRS)} s per query"
+
+
+ puts "Quering with $set..."
+ st = Time.now
+ assert_equal(RS, $jb.update("pcoll1", {"$set" => {"intv" => 1}}))
+ puts "Update query ($set) time: #{Time.now - st}"
+
+ puts "Quering with $inc..."
+ st = Time.now
+ assert_equal(RS, $jb.update("pcoll1", {"$inc" => {"intv" => 1}}))
+ puts "Update query ($inc) time: #{Time.now - st}"
+ assert_equal(RS, $jb.find("pcoll1", {"intv" => 2}, :onlycount => true))
end
end