mirror of https://github.com/lukechilds/node.git
Browse Source
When create Buffer from a Buffer will copy data from old to new even though length is zero. This patch can improve edge case 4x faster. following is benchmark results. new: buffers/buffer_zero.js n=1024: 2463.53891 old: buffers/buffer_zero.js n=1024: 618.70801 PR-URL: https://github.com/nodejs/node/pull/4326 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>process-exit-stdio-flushing
Jackson Tian
9 years ago
committed by
James M Snell
2 changed files with 22 additions and 0 deletions
@ -0,0 +1,18 @@ |
|||||
|
'use strict'; |
||||
|
|
||||
|
const common = require('../common.js'); |
||||
|
|
||||
|
const bench = common.createBenchmark(main, { |
||||
|
n: [1024] |
||||
|
}); |
||||
|
|
||||
|
const zero = new Buffer(0); |
||||
|
|
||||
|
function main(conf) { |
||||
|
var n = +conf.n; |
||||
|
bench.start(); |
||||
|
for (let i = 0; i < n * 1024; i++) { |
||||
|
new Buffer(zero); |
||||
|
} |
||||
|
bench.end(n); |
||||
|
} |
Loading…
Reference in new issue