Skip to content

Instantly share code, notes, and snippets.

@caridy
Created November 20, 2012 17:44
Show Gist options
  • Save caridy/4119541 to your computer and use it in GitHub Desktop.
Save caridy/4119541 to your computer and use it in GitHub Desktop.
YUI.JSON.* vs JSON.* in Node.JS
var Y = require('yui/json'),
microtime = require('microtime'),
i,
t,
obj = {
foo: {
bar: {
baz: 'token'
}
}
},
str = JSON.stringify({
foo: {
bar: {
baz: 'token'
}
}
});
// low level
t = microtime.now();
for (i = 0; i < 100000; i += 1) {
obj.foo.bar.baz = i;
JSON.stringify(obj);
}
console.log('stringify native: ', microtime.now() - t);
// yui implementation
t = microtime.now();
for (i = 0; i < 100000; i += 1) {
obj.foo.bar.baz = i;
Y.JSON.stringify(obj);
}
console.log('Y.JSON.stringify: ', microtime.now() - t);
// low level
t = microtime.now();
for (i = 0; i < 100000; i += 1) {
str.replace('token', i);
JSON.parse(str);
}
console.log('parse native: ', microtime.now() - t);
// yui implementation
t = microtime.now();
for (i = 0; i < 100000; i += 1) {
str.replace('token', i);
Y.JSON.parse(str);
}
console.log('Y.JSON.parse: ', microtime.now() - t);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment