I was considering using BSON as a serialization format outside of
mongodb in a ruby1.9.1 format.
But, I'm concerned that BSON comes up significantly slower on larger
objects.
Any plans to address this?
The data: here's a quick test of bson_ext (1.0.1) against json (ext)
(1.4.3) on ruby1.9.1.
irb1.9
require 'json'
require 'bson'
require 'benchmark'
[ JSON.parser, JSON.generator ]
=> [JSON::Ext::Parser, JSON::Ext::Generator]
x={'a' => 23, 'b' => 1}
y={'a' => {'23' => 44}, 'b' => [1,2,3]}
Benchmark.bm(12) do |b|
b.report("JSON flat"){ 100_000.times
{ JSON.parse(JSON.unparse(x)) } }
b.report("BSON flat")
{ 100_000.times{ BSON.deserialize(BSON.serialize(x)) } }
b.report("JSON nested"){ 100_000.times
{ JSON.parse(JSON.unparse(y)) } }
b.report("BSON nested")
{ 100_000.times{ BSON.deserialize(BSON.serialize(y)) } }
end
user system total real
JSON flat 6.290000 0.020000 6.310000 ( 6.433589)
BSON flat 2.560000 0.020000 2.580000 ( 2.611101)
JSON nested 6.920000 0.020000 6.940000 ( 6.995786)
BSON nested 7.400000 0.010000 7.410000 ( 7.541154)
ENCODE ONLY:
Benchmark.bm(12) do |b|
b.report("JSON flat"){ 100_000.times { JSON.unparse(x) } }
b.report("BSON flat"){ 100_000.times{ BSON.serialize(x) } }
b.report("JSON nested"){ 100_000.times { JSON.unparse(y) } }
b.report("BSON nested"){ 100_000.times{ BSON.serialize(y) } }
end
user system total real
JSON flat 5.060000 0.010000 5.070000 ( 5.144688)
BSON flat 1.050000 0.000000 1.050000 ( 1.057095)
JSON nested 5.420000 0.010000 5.430000 ( 5.431371)
BSON nested 5.130000 0.000000 5.130000 ( 5.168057)
DECODE ONLY:
Benchmark.bm(12) do |b|
b.report("JSON flat"){ x1 = JSON.unparse(x); 100_000.times
{ JSON.parse(x1) } }
b.report("BSON flat"){ x1 = BSON.serialize(x);
100_000.times{ BSON.deserialize(x1) } }
b.report("JSON nested"){ y1 = JSON.unparse(y); 100_000.times
{ JSON.parse(y1) } }
b.report("BSON nested"){ y1 = BSON.serialize(y);
100_000.times{ BSON.deserialize(y1) } }
end
user system total real
JSON flat 0.960000 0.010000 0.970000 ( 0.966397)
BSON flat 1.410000 0.000000 1.410000 ( 1.408494)
JSON nested 1.360000 0.000000 1.360000 ( 1.411166)
BSON nested 2.060000 0.000000 2.060000 ( 2.124530)
z = Hash[* ("001".."100").zip(1..100).flatten ]
zz = Hash[* ("001".."100").map(&:to_sym).zip(1..100).flatten ]
Benchmark.bm(12) do |b|
b.report("JSON large"){ 10_000.times
{ JSON.parse(JSON.unparse(z)) } }
b.report("BSON large")
{ 10_000.times{ BSON.deserialize(BSON.serialize(z)) } }
b.report("JSON lgsym"){ 10_000.times
{ JSON.parse(JSON.unparse(zz)) } }
b.report("BSON lgsym")
{ 10_000.times{ BSON.deserialize(BSON.serialize(zz)) } }
end
user system total real
JSON large 3.800000 0.000000 3.800000 ( 3.901924)
BSON large 5.130000 0.010000 5.140000 ( 5.209777)
JSON lgsym 4.390000 0.000000 4.390000 ( 4.396391)
BSON lgsym 15.260000 0.020000 15.280000 ( 15.521184)
--
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To post to this group, send email to
mongod...@googlegroups.com.
To unsubscribe from this group, send email to
mongodb-user...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/mongodb-user?hl=en.