Just insert test.
#!/usr/bin/ruby require 'rubygems' require 'benchmark' require 'mongo' require 'mysql' # init benchmark cycle def cycle 10000.times{ |i| doc = { "text" => "i am any text and a little tail with me: #{i}", "count" => i, "coords" => {"x" => 203 + i, "y" => 102 + i} } yield doc } end # init mysql mysql = Mysql.new('localhost', 'testuser', 'testpass', 'test') mysql.query("DROP TABLE IF EXISTS `insert_bm`") mysql.query("DROP TABLE IF EXISTS `insert_bm_coords`") mysql.query("CREATE TABLE `insert_bm_coords`( `id` int unsigned not null auto_increment, `x` int not null, `y` int not null, PRIMARY KEY (`id`) )") mysql.query("CREATE TABLE `insert_bm`( `id` int unsigned not null auto_increment, `text` varchar(255) not null, `count` int not null, `coords_id` int unsigned not null, PRIMARY KEY (`id`) )") # init mongodb mongo_db = Mongo::Connection.new.db("ololo_db") mongo_db.collection("beta").drop mongo = mongo_db.collection("beta") # do benchmarking Benchmark.bm {|x| x.report("mysql:") { cycle{|doc| mysql.query("INSERT insert_bm_coords(x,y) VALUES(#{doc["coords"]["x"]}, #{doc["coords"]["y"]})") mysql.query("INSERT insert_bm(text, count, coords_id) VALUES('#{doc["text"]}', #{doc["count"]}, #{mysql.insert_id()})") } } x.report("mongodb:") { cycle{|doc| mongo.insert(doc) } } }
Result:
10_000:
user system total real
mysql: 0.300000 0.150000 0.450000 ( 1.763819)
mongodb: 5.690000 0.680000 6.370000 ( 7.201129)
1_000_000:
user system total real
mysql: 30.960000 12.950000 43.910000 (179.318003)
mongodb:569.650000 18.410000 588.060000 (678.889538)
UPDATE: after installing C extension (`gem install mongo_ext`).
I'm confused. Can anybody explain it?
10_000:
user system total real
mysql: 0.280000 0.110000 0.390000 ( 1.679100)
mongodb: 3.110000 0.270000 3.380000 ( 4.089022)
1_000_000:
user system total real
mysql: 32.400000 13.030000 45.430000 (179.684186)
mongodb:326.150000 17.000000 343.150000 (423.631974)
Что-то тут не так, учитывая заявления о скорости MongoDB.
Кто-то может подтвердить или опровергнуть?
UPDATE: here is explanation: http://blog.knopkodav.ru/2009/11/mongo-mysql-ruby-and-php.html