Skip to content

Instantly share code, notes, and snippets.

@fengmk2
Created August 14, 2012 11:13
Show Gist options
  • Save fengmk2/3348243 to your computer and use it in GitHub Desktop.
Save fengmk2/3348243 to your computer and use it in GitHub Desktop.
xml2json benchmark
var Benchmark = require('benchmark');
var xml2json = require('xml2json');
var fs = require('fs');
var suite = new Benchmark.Suite();
var xml = '\
<doc>\
<Column>\
<Name>shit</Name>\
<Value type="STRING"> abc\
asdf\
a </Value>\
</Column>\
<Column><Name>foo</Name><Value type="STRING"></Value></Column>\
<Column><Name>foo2</Name><Value type="STRING" /></Column>\
<Column><Name>bar</Name><Value type="STRING"> </Value></Column>\
<Column PK="true"><Name>uid</Name><Value type="STRING">god</Value></Column>\
</doc>\
';
suite
.add('toJson() with {object: true, space: true}', function () {
var json = xml2json.toJson(xml, {object: true, space: true});
})
.add('toJson() with {object: true, space: false}', function () {
var json = xml2json.toJson(xml, {object: true, space: false});
})
.add('toJson() with {}', function () {
var json = xml2json.toJson(xml);
})
// add listeners
.on('cycle', function (event, bench) {
console.log(String(bench));
})
.on('complete', function () {
console.log('Fastest is ' + this.filter('fastest').pluck('name'));
})
.run();
@fengmk2
Copy link
Author

fengmk2 commented Aug 14, 2012

$ node benchmark.js 
toJson() with {object: true, space: true} x 4,163 ops/sec ±5.43% (72 runs sampled)
toJson() with {object: true, space: false} x 4,071 ops/sec ±12.40% (68 runs sampled)
toJson() with {} x 3,778 ops/sec ±10.87% (70 runs sampled)
Fastest is toJson() with {object: true, space: true},toJson() with {object: true, space: false},toJson() with {}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment