#50 - performance test
authorFedor Yudanov <fedwiz@academ.org>
Thu, 18 Apr 2013 10:45:12 +0000 (17:45 +0700)
committerFedor Yudanov <fedwiz@academ.org>
Thu, 18 Apr 2013 10:45:12 +0000 (17:45 +0700)
rbejdb/test/t3.rb

index 46426ab..80ac3b2 100644 (file)
@@ -13,7 +13,7 @@ $jb = EJDB.open("tdbt3", EJDB::JBOWRITER | EJDB::JBOCREAT | EJDB::JBOTRUNC)
 
 class EJDBAdvancedTestUnit < Test::Unit::TestCase
   RS = 100000
-  QRS = 100000
+  QRS = 10000
 
   def test_ejdbadv1_performance
     assert_not_nil $jb
@@ -43,16 +43,47 @@ class EJDBAdvancedTestUnit < Test::Unit::TestCase
     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