Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

file 59 lines (52 sloc) 1.227 kb
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 53 54 55 56 57 58 59
#!/usr/bin/env ruby

$LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
require 'mongo'

include Mongo

TRIALS = 100000

def encode(doc)
  t0 = Time.new
  b = Mongo::BSON_CODER.new
  TRIALS.times { |i|
    b = Mongo::BSON_CODER.new
    b.serialize doc
  }
  print "took: #{Time.now.to_f - t0.to_f}\n"
  return b
end

def decode(bson)
  t0 = Time.new
  doc = nil
  TRIALS.times { |i|
    doc = bson.deserialize
  }
  print "took: #{Time.now.to_f - t0.to_f}\n"
  return doc
end

TEST_CASES = [{},
              {
                "hello" => "world"
              },
              {
                "hello" => "world",
                "mike" => "something",
                "here's" => "another"
              },
              {
                "int" => 200,
                "bool" => true,
                "an int" => 20,
                "a bool" => false
              },
              {
                "this" => 5,
                "is" => {"a" => true},
                "big" => [true, 5.5],
                "object" => nil
              }]

TEST_CASES.each { |doc|
  print "case #{doc.inspect}\n"
  print "enc bson\n"
  enc_bson = encode(doc)
  print "dec bson\n"
  raise "FAIL" unless doc == decode(enc_bson)
}
Something went wrong with that request. Please try again.