Skip to content

Instantly share code, notes, and snippets.

@indutny

indutny/1.js Secret

Created July 24, 2015 05:25
Show Gist options
  • Save indutny/76579b69f072e3a25155 to your computer and use it in GitHub Desktop.
Save indutny/76579b69f072e3a25155 to your computer and use it in GitHub Desktop.
var Buffer = require('buffer').Buffer;
var a = new Buffer(256);
var b = new Buffer(256);
a.fill(0);
b.fill(0);
var ITER = 1000000;
function compare(a, b) {
for (var j = 0; j < a.length; j++)
if (a[j] !== b[j])
return -1;
return 0;
}
console.time('js');
for (var i = 0; i < ITER; i++) {
compare(a, b);
}
console.timeEnd('js');
console.time('c++');
for (var i = 0; i < ITER; i++) {
Buffer.compare(a, b);
}
console.timeEnd('c++');
js: 210ms
c++: 66ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment