New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
What's up with the benchmarks? :( #48
Comments
There are several things wrong with your benchmark. The first and most important is that you're not comparing equivalent operations: you should be comparing The other major problem is that micro-benchmarks are tricky to get right. v8 has many optimizations which can render your benchmark meaningless. If we tweak your code to remove any obvious pitfalls (see below), we get:
var avro = require('avsc');
var schema = {
name: 'Pet',
type: 'record',
fields: [
{name: 'kind', type: {name: 'Kind', type: 'enum', symbols: ['CAT', 'DOG']}},
{name: 'age', type: 'int'} // To simplify preventing getting hoisted out of the loop.
]
};
var type = avro.parse(schema); // Done once upfront.
var start = Date.now();
for (var i = 0; i < 5000000; i++) {
if (JSON.stringify({age: i, kind: 'CAT'}).length < 2) {
throw new Error();
}
}
var stop = Date.now();
console.log("\t JSON: " + (stop - start) + "ms");
start = Date.now();
for (var i = 0; i < 5000000; i++) {
if (type.toBuffer({age: i, kind: 'CAT'}).length < 2) {
throw new Error();
}
}
stop = Date.now();
console.log("\t Avro: " + (stop - start) + "ms"); |
Awww. I'm an idiot. Well, I'll be using Avro from now on then :) Thanks for the explanation haha. Cannot wait to get this puppy across our binary websockets, she will fly. |
Here is code:
Results:
I thought Avro was going to perform faster than JSON?
The text was updated successfully, but these errors were encountered: