Created
November 2, 2011 22:28
-
-
Save justmoon/1335137 to your computer and use it in GitHub Desktop.
Node.js Buffer#copy performance
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
Node.js 0.4.12 | |
-------------- | |
Buffer (10 bytes): | |
Buffer#copy x 233,570 ops/sec ±0.96% (74 runs sampled) | |
Buffer[] x 1,152,607 ops/sec ±2.57% (72 runs sampled) | |
Fastest is Buffer[] | |
Buffer (50 bytes): | |
Buffer#copy x 219,542 ops/sec ±0.69% (80 runs sampled) | |
Buffer[] x 698,666 ops/sec ±1.14% (74 runs sampled) | |
Fastest is Buffer[] | |
Buffer (250 bytes): | |
Buffer#copy x 187,207 ops/sec ±1.46% (70 runs sampled) | |
Buffer[] x 222,829 ops/sec ±2.38% (75 runs sampled) | |
Fastest is Buffer[] | |
Buffer (1000 bytes): | |
Buffer#copy x 144,450 ops/sec ±1.59% (76 runs sampled) | |
Buffer[] x 68,145 ops/sec ±1.91% (75 runs sampled) | |
Fastest is Buffer#copy | |
Node.js 0.5.10-pre (c8646e0c4159aa53b2ae94d1b69850ce5fa62ca2) | |
------------------------------------------------------------- | |
Buffer (10 bytes): | |
Buffer#copy x 1,454,959 ops/sec ±0.77% (78 runs sampled) | |
Buffer[] x 2,387,791 ops/sec ±0.72% (78 runs sampled) | |
Fastest is Buffer[] | |
Buffer (50 bytes): | |
Buffer#copy x 1,334,755 ops/sec ±0.57% (79 runs sampled) | |
Buffer[] x 1,794,093 ops/sec ±1.77% (79 runs sampled) | |
Fastest is Buffer[] | |
Buffer (250 bytes): | |
Buffer#copy x 1,004,576 ops/sec ±1.64% (69 runs sampled) | |
Buffer[] x 954,116 ops/sec ±3.93% (71 runs sampled) | |
Fastest is Buffer#copy | |
Buffer (1000 bytes): | |
Buffer#copy x 560,584 ops/sec ±7.60% (66 runs sampled) | |
Buffer[] x 368,210 ops/sec ±4.48% (74 runs sampled) | |
Fastest is Buffer#copy |
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 suite = new (require('benchmark').Suite); | |
var subject = new Buffer(10); | |
// tests | |
suite.add('Buffer#copy', function() { | |
var target = new Buffer(subject.length); | |
subject.copy(target); | |
}) | |
.add('Buffer[]', function() { | |
var target = new Buffer(subject.length); | |
for (var i = 0, l = subject.length; i < l; i++) { | |
target[i] = subject[i]; | |
} | |
}) | |
// add listeners | |
.on('cycle', function(event, bench) { | |
console.log(String(bench)); | |
}) | |
.on('complete', function() { | |
console.log('Fastest is ' + this.filter('fastest').pluck('name')); | |
}) | |
// run async | |
.run({ 'async': true }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment