-
-
Save indutny/76579b69f072e3a25155 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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++'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
js: 210ms | |
c++: 66ms |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment