diff options
author | James M Snell <jasnell@gmail.com> | 2016-01-26 02:00:06 +0300 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2016-03-16 18:34:02 +0300 |
commit | 85ab4a5f1281c4e1dd06450ac7bd3250326267fa (patch) | |
tree | 7a51edfc5d6efc231cf821d575c9ca4a26d0545f /benchmark | |
parent | 90a5fc20be22b4278a01bc58acba0cb732da0140 (diff) |
buffer: add .from(), .alloc() and .allocUnsafe()
Several changes:
* Soft-Deprecate Buffer() constructors
* Add `Buffer.from()`, `Buffer.alloc()`, and `Buffer.allocUnsafe()`
* Add `--zero-fill-buffers` command line option
* Add byteOffset and length to `new Buffer(arrayBuffer)` constructor
* buffer.fill('') previously had no effect, now zero-fills
* Update the docs
PR-URL: https://github.com/nodejs/node/pull/4682
Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
Diffstat (limited to 'benchmark')
38 files changed, 98 insertions, 79 deletions
diff --git a/benchmark/buffers/buffer-base64-decode.js b/benchmark/buffers/buffer-base64-decode.js index 36094f632d4..3497bfd05fd 100644 --- a/benchmark/buffers/buffer-base64-decode.js +++ b/benchmark/buffers/buffer-base64-decode.js @@ -8,7 +8,7 @@ function main(conf) { const s = 'abcd'.repeat(8 << 20); s.match(/./); // Flatten string. assert.equal(s.length % 4, 0); - const b = Buffer(s.length / 4 * 3); + const b = Buffer.allocUnsafe(s.length / 4 * 3); b.write(s, 0, s.length, 'base64'); bench.start(); for (var i = 0; i < 32; i += 1) b.base64Write(s, 0, s.length); diff --git a/benchmark/buffers/buffer-base64-encode.js b/benchmark/buffers/buffer-base64-encode.js index 8e2eec3cf5b..930dc82b6b9 100644 --- a/benchmark/buffers/buffer-base64-encode.js +++ b/benchmark/buffers/buffer-base64-encode.js @@ -5,7 +5,7 @@ var bench = common.createBenchmark(main, {}); function main(conf) { var N = 64 * 1024 * 1024; - var b = Buffer(N); + var b = Buffer.allocUnsafe(N); var s = ''; var i; for (i = 0; i < 256; ++i) s += String.fromCharCode(i); diff --git a/benchmark/buffers/buffer-bytelength.js b/benchmark/buffers/buffer-bytelength.js index 50f420f412d..273115b3def 100644 --- a/benchmark/buffers/buffer-bytelength.js +++ b/benchmark/buffers/buffer-bytelength.js @@ -28,7 +28,7 @@ function main(conf) { strings.push(data); } else if (encoding === 'base64') { // Base64 strings will be much longer than their UTF8 counterparts - strings.push(new Buffer(data, 'utf8').toString('base64')); + strings.push(Buffer.from(data, 'utf8').toString('base64')); } } diff --git a/benchmark/buffers/buffer-compare.js b/benchmark/buffers/buffer-compare.js index c83bb67fa24..84faf84e34a 100644 --- a/benchmark/buffers/buffer-compare.js +++ b/benchmark/buffers/buffer-compare.js @@ -7,10 +7,10 @@ var bench = common.createBenchmark(main, { }); function main(conf) { - var iter = (conf.millions >>> 0) * 1e6; - var size = (conf.size >>> 0); - var b0 = new Buffer(size).fill('a'); - var b1 = new Buffer(size).fill('a'); + const iter = (conf.millions >>> 0) * 1e6; + const size = (conf.size >>> 0); + const b0 = Buffer.alloc(size, 'a'); + const b1 = Buffer.alloc(size, 'a'); b1[size - 1] = 'b'.charCodeAt(0); diff --git a/benchmark/buffers/buffer-creation.js b/benchmark/buffers/buffer-creation.js index dfb68467cc5..e0e64d6934d 100644 --- a/benchmark/buffers/buffer-creation.js +++ b/benchmark/buffers/buffer-creation.js @@ -1,20 +1,59 @@ 'use strict'; const SlowBuffer = require('buffer').SlowBuffer; -var common = require('../common.js'); -var bench = common.createBenchmark(main, { - type: ['fast', 'slow'], - len: [10, 1024], +const common = require('../common.js'); +const assert = require('assert'); +const bench = common.createBenchmark(main, { + type: [ + 'fast-alloc', + 'fast-alloc-fill', + 'fast-allocUnsafe', + 'slow', + 'buffer()'], + len: [10, 1024, 2048, 4096, 8192], n: [1024] }); function main(conf) { - var len = +conf.len; - var n = +conf.n; - var clazz = conf.type === 'fast' ? Buffer : SlowBuffer; - bench.start(); - for (var i = 0; i < n * 1024; i++) { - new clazz(len); + const len = +conf.len; + const n = +conf.n; + switch (conf.type) { + case 'fast-alloc': + bench.start(); + for (let i = 0; i < n * 1024; i++) { + Buffer.alloc(len); + } + bench.end(n); + break; + case 'fast-alloc-fill': + bench.start(); + for (let i = 0; i < n * 1024; i++) { + Buffer.alloc(len, 0); + } + bench.end(n); + break; + case 'fast-allocUnsafe': + bench.start(); + for (let i = 0; i < n * 1024; i++) { + Buffer.allocUnsafe(len); + } + bench.end(n); + break; + case 'slow': + bench.start(); + for (let i = 0; i < n * 1024; i++) { + SlowBuffer(len); + } + bench.end(n); + break; + case 'buffer()': + bench.start(); + for (let i = 0; i < n * 1024; i++) { + Buffer(len); + } + bench.end(n); + break; + default: + assert.fail(null, null, 'Should not get here'); } - bench.end(n); } diff --git a/benchmark/buffers/buffer-indexof.js b/benchmark/buffers/buffer-indexof.js index 6f10033020b..380f40b23d8 100644 --- a/benchmark/buffers/buffer-indexof.js +++ b/benchmark/buffers/buffer-indexof.js @@ -27,11 +27,11 @@ function main(conf) { } if (encoding === 'ucs2') { - aliceBuffer = new Buffer(aliceBuffer.toString(), encoding); + aliceBuffer = Buffer.from(aliceBuffer.toString(), encoding); } if (conf.type === 'buffer') { - search = new Buffer(new Buffer(search).toString(), encoding); + search = Buffer.from(Buffer.from(search).toString(), encoding); } bench.start(); diff --git a/benchmark/buffers/buffer-slice.js b/benchmark/buffers/buffer-slice.js index 70cf3a705c0..13dbf6a59b7 100644 --- a/benchmark/buffers/buffer-slice.js +++ b/benchmark/buffers/buffer-slice.js @@ -7,7 +7,7 @@ var bench = common.createBenchmark(main, { n: [1024] }); -var buf = new Buffer(1024); +var buf = Buffer.allocUnsafe(1024); var slowBuf = new SlowBuffer(1024); function main(conf) { diff --git a/benchmark/buffers/buffer-tostring.js b/benchmark/buffers/buffer-tostring.js index 937a84b267e..99ae0ec0779 100644 --- a/benchmark/buffers/buffer-tostring.js +++ b/benchmark/buffers/buffer-tostring.js @@ -12,7 +12,7 @@ function main(conf) { const arg = conf.arg === 'true'; const len = conf.len | 0; const n = conf.n | 0; - const buf = Buffer(len).fill(42); + const buf = Buffer.alloc(len, 42); var i; bench.start(); diff --git a/benchmark/buffers/buffer_zero.js b/benchmark/buffers/buffer_zero.js index 461378758b5..4a63695657b 100644 --- a/benchmark/buffers/buffer_zero.js +++ b/benchmark/buffers/buffer_zero.js @@ -6,13 +6,13 @@ const bench = common.createBenchmark(main, { n: [1024] }); -const zero = new Buffer(0); +const zero = Buffer.alloc(0); function main(conf) { var n = +conf.n; bench.start(); for (let i = 0; i < n * 1024; i++) { - new Buffer(zero); + Buffer.from(zero); } bench.end(n); } diff --git a/benchmark/crypto/aes-gcm-throughput.js b/benchmark/crypto/aes-gcm-throughput.js index fc379b21b74..0cb32689510 100644 --- a/benchmark/crypto/aes-gcm-throughput.js +++ b/benchmark/crypto/aes-gcm-throughput.js @@ -9,10 +9,10 @@ var bench = common.createBenchmark(main, { }); function main(conf) { - var message = (new Buffer(conf.len)).fill('b'); + var message = Buffer.alloc(conf.len, 'b'); var key = crypto.randomBytes(keylen[conf.cipher]); var iv = crypto.randomBytes(12); - var associate_data = (new Buffer(16)).fill('z'); + var associate_data = Buffer.alloc(16, 'z'); bench.start(); AEAD_Bench(conf.cipher, message, associate_data, key, iv, conf.n, conf.len); } diff --git a/benchmark/crypto/cipher-stream.js b/benchmark/crypto/cipher-stream.js index 5da6f2481ec..b8e1622bf9f 100644 --- a/benchmark/crypto/cipher-stream.js +++ b/benchmark/crypto/cipher-stream.js @@ -48,8 +48,7 @@ function main(conf) { encoding = 'utf8'; break; case 'buf': - message = new Buffer(conf.len); - message.fill('b'); + message = Buffer.alloc(conf.len, 'b'); break; default: throw new Error('unknown message type: ' + conf.type); diff --git a/benchmark/crypto/hash-stream-creation.js b/benchmark/crypto/hash-stream-creation.js index 4bcd37f00aa..e7fcde3aa60 100644 --- a/benchmark/crypto/hash-stream-creation.js +++ b/benchmark/crypto/hash-stream-creation.js @@ -33,8 +33,7 @@ function main(conf) { encoding = 'utf8'; break; case 'buf': - message = new Buffer(conf.len); - message.fill('b'); + message = Buffer.alloc(conf.len, 'b'); break; default: throw new Error('unknown message type: ' + conf.type); @@ -58,7 +57,7 @@ function legacyWrite(algo, message, encoding, writes, len, outEnc) { // include buffer creation costs for older versions if (outEnc === 'buffer' && typeof res === 'string') - res = new Buffer(res, 'binary'); + res = Buffer.from(res, 'binary'); } bench.end(gbits); diff --git a/benchmark/crypto/hash-stream-throughput.js b/benchmark/crypto/hash-stream-throughput.js index 050bbeb1ae5..732c2b89c74 100644 --- a/benchmark/crypto/hash-stream-throughput.js +++ b/benchmark/crypto/hash-stream-throughput.js @@ -32,8 +32,7 @@ function main(conf) { encoding = 'utf8'; break; case 'buf': - message = new Buffer(conf.len); - message.fill('b'); + message = Buffer.alloc(conf.len, 'b'); break; default: throw new Error('unknown message type: ' + conf.type); diff --git a/benchmark/crypto/rsa-encrypt-decrypt-throughput.js b/benchmark/crypto/rsa-encrypt-decrypt-throughput.js index cf0579134cf..4d98f9e2d5d 100644 --- a/benchmark/crypto/rsa-encrypt-decrypt-throughput.js +++ b/benchmark/crypto/rsa-encrypt-decrypt-throughput.js @@ -23,8 +23,7 @@ var bench = common.createBenchmark(main, { }); function main(conf) { - var message = (new Buffer(conf.len)).fill('b'); - + var message = Buffer.alloc(conf.len, 'b'); bench.start(); StreamWrite(conf.algo, conf.keylen, message, conf.n, conf.len); } diff --git a/benchmark/crypto/rsa-sign-verify-throughput.js b/benchmark/crypto/rsa-sign-verify-throughput.js index 779cc8bca1c..c5db94687a1 100644 --- a/benchmark/crypto/rsa-sign-verify-throughput.js +++ b/benchmark/crypto/rsa-sign-verify-throughput.js @@ -24,8 +24,7 @@ var bench = common.createBenchmark(main, { }); function main(conf) { - var message = (new Buffer(conf.len)).fill('b'); - + var message = Buffer.alloc(conf.len, 'b'); bench.start(); StreamWrite(conf.algo, conf.keylen, message, conf.writes, conf.len); } diff --git a/benchmark/dgram/array-vs-concat.js b/benchmark/dgram/array-vs-concat.js index ee74ff66b92..e47229811e8 100644 --- a/benchmark/dgram/array-vs-concat.js +++ b/benchmark/dgram/array-vs-concat.js @@ -31,7 +31,7 @@ function main(conf) { chunk = []; for (var i = 0; i < chunks; i++) { - chunk.push(new Buffer(Math.round(len / chunks))); + chunk.push(Buffer.allocUnsafe(Math.round(len / chunks))); } server(); diff --git a/benchmark/dgram/multi-buffer.js b/benchmark/dgram/multi-buffer.js index 22c30594196..e7292feb1f9 100644 --- a/benchmark/dgram/multi-buffer.js +++ b/benchmark/dgram/multi-buffer.js @@ -31,7 +31,7 @@ function main(conf) { chunk = []; for (var i = 0; i < chunks; i++) { - chunk.push(new Buffer(Math.round(len / chunks))); + chunk.push(Buffer.allocUnsafe(Math.round(len / chunks))); } server(); diff --git a/benchmark/dgram/offset-length.js b/benchmark/dgram/offset-length.js index c11c465f5cf..15d9a3d0ee9 100644 --- a/benchmark/dgram/offset-length.js +++ b/benchmark/dgram/offset-length.js @@ -25,7 +25,7 @@ function main(conf) { len = +conf.len; num = +conf.num; type = conf.type; - chunk = new Buffer(len); + chunk = Buffer.allocUnsafe(len); server(); } diff --git a/benchmark/dgram/single-buffer.js b/benchmark/dgram/single-buffer.js index 765311a72f3..2676e0e74cf 100644 --- a/benchmark/dgram/single-buffer.js +++ b/benchmark/dgram/single-buffer.js @@ -25,7 +25,7 @@ function main(conf) { len = +conf.len; num = +conf.num; type = conf.type; - chunk = new Buffer(len); + chunk = Buffer.allocUnsafe(len); server(); } diff --git a/benchmark/fs-write-stream-throughput.js b/benchmark/fs-write-stream-throughput.js index 4c767cf666e..f1c8d3cc1a6 100644 --- a/benchmark/fs-write-stream-throughput.js +++ b/benchmark/fs-write-stream-throughput.js @@ -45,8 +45,7 @@ function runTest(dur, size, type) { chunk = new Array(size + 1).join('a'); break; case 'buffer': - chunk = new Buffer(size); - chunk.fill('a'); + chunk = Buffer.alloc(size, 'a'); break; } diff --git a/benchmark/fs/read-stream-throughput.js b/benchmark/fs/read-stream-throughput.js index c305485cd5f..bc55e44c1a1 100644 --- a/benchmark/fs/read-stream-throughput.js +++ b/benchmark/fs/read-stream-throughput.js @@ -60,7 +60,7 @@ function runTest() { } function makeFile() { - var buf = new Buffer(filesize / 1024); + var buf = Buffer.allocUnsafe(filesize / 1024); if (encoding === 'utf8') { // ü for (var i = 0; i < buf.length; i++) { diff --git a/benchmark/fs/readfile.js b/benchmark/fs/readfile.js index 0f39f64f57c..cdb36d065f1 100644 --- a/benchmark/fs/readfile.js +++ b/benchmark/fs/readfile.js @@ -17,8 +17,7 @@ var bench = common.createBenchmark(main, { function main(conf) { var len = +conf.len; try { fs.unlinkSync(filename); } catch (e) {} - var data = new Buffer(len); - data.fill('x'); + var data = Buffer.alloc(len, 'x'); fs.writeFileSync(filename, data); data = null; diff --git a/benchmark/fs/write-stream-throughput.js b/benchmark/fs/write-stream-throughput.js index 4f41d2b4bb4..812dc369d7b 100644 --- a/benchmark/fs/write-stream-throughput.js +++ b/benchmark/fs/write-stream-throughput.js @@ -21,8 +21,7 @@ function main(conf) { var chunk; switch (type) { case 'buf': - chunk = new Buffer(size); - chunk.fill('b'); + chunk = Buffer.alloc(size, 'b'); break; case 'asc': chunk = new Array(size + 1).join('a'); diff --git a/benchmark/http/bench-parser.js b/benchmark/http/bench-parser.js index 989d9a994fa..0a78f3ffcf2 100644 --- a/benchmark/http/bench-parser.js +++ b/benchmark/http/bench-parser.js @@ -25,7 +25,7 @@ function main(conf) { } header += CRLF; - processHeader(new Buffer(header), n); + processHeader(Buffer.from(header), n); } diff --git a/benchmark/http/chunked.js b/benchmark/http/chunked.js index 642f2962cdc..a61978c7322 100644 --- a/benchmark/http/chunked.js +++ b/benchmark/http/chunked.js @@ -18,8 +18,7 @@ var bench = common.createBenchmark(main, { function main(conf) { const http = require('http'); - var chunk = new Buffer(conf.size); - chunk.fill('8'); + var chunk = Buffer.alloc(conf.size, '8'); var args = ['-d', '10s', '-t', 8, '-c', conf.c]; diff --git a/benchmark/http/client-request-body.js b/benchmark/http/client-request-body.js index befa3811ddd..8d7fae44c1e 100644 --- a/benchmark/http/client-request-body.js +++ b/benchmark/http/client-request-body.js @@ -19,8 +19,7 @@ function main(conf) { var chunk; switch (conf.type) { case 'buf': - chunk = new Buffer(len); - chunk.fill('x'); + chunk = Buffer.alloc(len, 'x'); break; case 'utf': encoding = 'utf8'; diff --git a/benchmark/http/end-vs-write-end.js b/benchmark/http/end-vs-write-end.js index 4e12e543f0b..0cdc88111de 100644 --- a/benchmark/http/end-vs-write-end.js +++ b/benchmark/http/end-vs-write-end.js @@ -23,8 +23,7 @@ function main(conf) { var len = conf.kb * 1024; switch (conf.type) { case 'buf': - chunk = new Buffer(len); - chunk.fill('x'); + chunk = Buffer.alloc(len, 'x'); break; case 'utf': chunk = new Array(len / 2 + 1).join('ü'); diff --git a/benchmark/http_simple.js b/benchmark/http_simple.js index 0f36d3b6ce3..699f3b7c0b4 100644 --- a/benchmark/http_simple.js +++ b/benchmark/http_simple.js @@ -51,7 +51,7 @@ var server = module.exports = http.createServer(function(req, res) { if (n <= 0) throw new Error('buffer called with n <= 0'); if (storedBuffer[n] === undefined) { - storedBuffer[n] = new Buffer(n); + storedBuffer[n] = Buffer.allocUnsafe(n); for (i = 0; i < n; i++) { storedBuffer[n][i] = 'C'.charCodeAt(0); } diff --git a/benchmark/http_simple_auto.js b/benchmark/http_simple_auto.js index a2271ce1e06..7d209d8a113 100644 --- a/benchmark/http_simple_auto.js +++ b/benchmark/http_simple_auto.js @@ -47,7 +47,7 @@ var server = http.createServer(function(req, res) { n = parseInt(arg, 10); if (n <= 0) throw new Error('bytes called with n <= 0'); if (storedBuffer[n] === undefined) { - storedBuffer[n] = new Buffer(n); + storedBuffer[n] = Buffer.allocUnsafe(n); for (i = 0; i < n; i++) { storedBuffer[n][i] = 'C'.charCodeAt(0); } diff --git a/benchmark/net/net-c2s-cork.js b/benchmark/net/net-c2s-cork.js index 5d1c8a7495e..60b4542a47b 100644 --- a/benchmark/net/net-c2s-cork.js +++ b/benchmark/net/net-c2s-cork.js @@ -23,8 +23,7 @@ function main(conf) { switch (type) { case 'buf': - chunk = new Buffer(len); - chunk.fill('x'); + chunk = Buffer.alloc(len, 'x'); break; case 'utf': encoding = 'utf8'; diff --git a/benchmark/net/net-c2s.js b/benchmark/net/net-c2s.js index 370ff4f138c..d64a5517e8f 100644 --- a/benchmark/net/net-c2s.js +++ b/benchmark/net/net-c2s.js @@ -23,8 +23,7 @@ function main(conf) { switch (type) { case 'buf': - chunk = new Buffer(len); - chunk.fill('x'); + chunk = Buffer.alloc(len, 'x'); break; case 'utf': encoding = 'utf8'; diff --git a/benchmark/net/net-pipe.js b/benchmark/net/net-pipe.js index ea8af249a35..b6e95a8b75d 100644 --- a/benchmark/net/net-pipe.js +++ b/benchmark/net/net-pipe.js @@ -23,8 +23,7 @@ function main(conf) { switch (type) { case 'buf': - chunk = new Buffer(len); - chunk.fill('x'); + chunk = Buffer.alloc(len, 'x'); break; case 'utf': encoding = 'utf8'; diff --git a/benchmark/net/net-s2c.js b/benchmark/net/net-s2c.js index af40d8d58d8..2ef151f4ca4 100644 --- a/benchmark/net/net-s2c.js +++ b/benchmark/net/net-s2c.js @@ -23,8 +23,7 @@ function main(conf) { switch (type) { case 'buf': - chunk = new Buffer(len); - chunk.fill('x'); + chunk = Buffer.alloc(len, 'x'); break; case 'utf': encoding = 'utf8'; diff --git a/benchmark/net/tcp-raw-c2s.js b/benchmark/net/tcp-raw-c2s.js index e13af85c677..e9dd7ca6620 100644 --- a/benchmark/net/tcp-raw-c2s.js +++ b/benchmark/net/tcp-raw-c2s.js @@ -79,8 +79,7 @@ function client() { var chunk; switch (type) { case 'buf': - chunk = new Buffer(len); - chunk.fill('x'); + chunk = Buffer.alloc(len, 'x'); break; case 'utf': chunk = new Array(len / 2 + 1).join('ü'); diff --git a/benchmark/net/tcp-raw-pipe.js b/benchmark/net/tcp-raw-pipe.js index c05c816855e..fb8da5ea41f 100644 --- a/benchmark/net/tcp-raw-pipe.js +++ b/benchmark/net/tcp-raw-pipe.js @@ -77,8 +77,7 @@ function client() { var chunk; switch (type) { case 'buf': - chunk = new Buffer(len); - chunk.fill('x'); + chunk = Buffer.alloc(len, 'x'); break; case 'utf': chunk = new Array(len / 2 + 1).join('ü'); diff --git a/benchmark/net/tcp-raw-s2c.js b/benchmark/net/tcp-raw-s2c.js index 822a74c679d..a7ef40db83a 100644 --- a/benchmark/net/tcp-raw-s2c.js +++ b/benchmark/net/tcp-raw-s2c.js @@ -51,8 +51,7 @@ function server() { var chunk; switch (type) { case 'buf': - chunk = new Buffer(len); - chunk.fill('x'); + chunk = Buffer.alloc(len, 'x'); break; case 'utf': chunk = new Array(len / 2 + 1).join('ü'); diff --git a/benchmark/string_decoder/string-decoder.js b/benchmark/string_decoder/string-decoder.js index b10b0a6e9cb..705ef841032 100644 --- a/benchmark/string_decoder/string-decoder.js +++ b/benchmark/string_decoder/string-decoder.js @@ -9,7 +9,7 @@ var bench = common.createBenchmark(main, { n: [25e4] }); -var UTF_ALPHA = 'Blbrsyltety'; +var UTF_ALPHA = 'Blåbærsyltetøy'; var ASC_ALPHA = 'Blueberry jam'; function main(conf) { @@ -35,18 +35,18 @@ function main(conf) { for (i = 0; i < inLen; ++i) { if (i > 0 && (i % chunkLen) === 0 && !isBase64) { - chunks.push(new Buffer(str, encoding)); + chunks.push(Buffer.from(str, encoding)); str = ''; } str += alpha[i % alpha.length]; } if (str.length > 0 && !isBase64) - chunks.push(new Buffer(str, encoding)); + chunks.push(Buffer.from(str, encoding)); if (isBase64) { - str = new Buffer(str, 'utf8').toString('base64'); + str = Buffer.from(str, 'utf8').toString('base64'); while (str.length > 0) { var len = Math.min(chunkLen, str.length); - chunks.push(new Buffer(str.substring(0, len), 'utf8')); + chunks.push(Buffer.from(str.substring(0, len), 'utf8')); str = str.substring(len); } } diff --git a/benchmark/tls/throughput.js b/benchmark/tls/throughput.js index 7b545267ace..d0de99e7b54 100644 --- a/benchmark/tls/throughput.js +++ b/benchmark/tls/throughput.js @@ -23,8 +23,7 @@ function main(conf) { var chunk; switch (type) { case 'buf': - chunk = new Buffer(size); - chunk.fill('b'); + chunk = Buffer.alloc(size, 'b'); break; case 'asc': chunk = new Array(size + 1).join('a'); @@ -74,4 +73,3 @@ function main(conf) { server.close(); } } - |