Skip to content

Instantly share code, notes, and snippets.

@brettkiefer
Created April 19, 2011 16:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brettkiefer/928677 to your computer and use it in GitHub Desktop.
Save brettkiefer/928677 to your computer and use it in GitHub Desktop.
Put a 1MB string at the lowest level of a 700-level deep object, then serialize and deserialize it, shows node-mongodb-native dbson deserialization performance issue.
require.paths.unshift("../../lib");
var sys = require('sys'),
Buffer = require('buffer').Buffer,
BSON = require('./bson').BSON,
Buffer = require('buffer').Buffer,
BSONJS = require('mongodb/bson/bson').BSON,
BinaryParser = require('mongodb/bson/binary_parser').BinaryParser,
Long = require('mongodb/goog/math/long').Long,
ObjectID = require('mongodb/bson/bson').ObjectID,
Binary = require('mongodb/bson/bson').Binary,
Code = require('mongodb/bson/bson').Code,
DBRef = require('mongodb/bson/bson').DBRef,
assert = require('assert');
sys.puts("=== EXCEUTING TEST_DEEP_OBJ ===");
// Simple serialization and deserialization for an Object
var dt = new Date();
var oBig = {o: {}};
function aString(length) {
var str = '';
for (var i = 0; i < length; i++) {
str += 'a';
}
return str;
}
var x = aString(1000 * 1000);
var o = oBig.o;
for (var i = 0; i < 700; i++)
{
if (i == 699) o.x = x;
o.o = {};
o = o.o;
}
console.log(['About to serialize', (new Date()).getTime() - dt.getTime()]);
var big = BSON.serialize(oBig);
console.log(['Serialized', (new Date()).getTime() - dt.getTime()]);
BSON.deserialize(big);
console.log(['Deserialized', (new Date()).getTime() - dt.getTime()]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment