GeezerVison is showing github.com — benchmark: add benchmarks for encodings · nodejs/node@15c2ed9
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: benchmark/buffers/buffer-base64-decode.js +9-1Lines changed: 9 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -15,7 +15,15 @@ function main({ n, size }) { | 15 | 15 | assert.strictEqual(s.length % 4, 0); | 16 | 16 | const b = Buffer.allocUnsafe(encodedSize); | 17 | 17 | b.write(s, 0, encodedSize, 'base64'); | | 18 | + | | 19 | + let tmp; | | 20 | + | 18 | 21 | bench.start(); | 19 | | - for (let i = 0; i < n; i += 1) b.base64Write(s, 0, s.length); | | 22 | + | | 23 | + for (let i = 0; i < n; i += 1) | | 24 | + tmp = b.base64Write(s, 0, s.length); | | 25 | + | 20 | 26 | bench.end(n); | | 27 | + | | 28 | + assert.strictEqual(tmp, encodedSize); | 21 | 29 | } |
Collapse file Copy file name to clipboardExpand all lines: benchmark/buffers/buffer-base64-encode.js +10-1Lines changed: 10 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 21 | 21 |
| 22 | 22 | 'use strict'; | 23 | 23 | const common = require('../common.js'); | | 24 | +const assert = require('assert'); | 24 | 25 |
| 25 | 26 | const bench = common.createBenchmark(main, { | 26 | 27 | len: [64 * 1024 * 1024], | @@ -35,7 +36,15 @@ function main({ n, len }) { | 35 | 36 | let i; | 36 | 37 | for (i = 0; i < 256; ++i) s += String.fromCharCode(i); | 37 | 38 | for (i = 0; i < len; i += 256) b.write(s, i, 256, 'ascii'); | | 39 | + | | 40 | + let tmp; | | 41 | + | 38 | 42 | bench.start(); | 39 | | - for (i = 0; i < n; ++i) b.toString('base64'); | | 43 | + | | 44 | + for (i = 0; i < n; ++i) | | 45 | + tmp = b.toString('base64'); | | 46 | + | 40 | 47 | bench.end(n); | | 48 | + | | 49 | + assert.strictEqual(typeof tmp, 'string'); | 41 | 50 | } |
Collapse file Copy file name to clipboard +29Lines changed: 29 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +'use strict'; | | 2 | +const assert = require('assert'); | | 3 | +const common = require('../common.js'); | | 4 | + | | 5 | +const bench = common.createBenchmark(main, { | | 6 | + n: [32], | | 7 | + size: [8 << 20], | | 8 | +}); | | 9 | + | | 10 | +function main({ n, size }) { | | 11 | + const s = 'abcd'.repeat(size); | | 12 | + const encodedSize = s.length * 3 / 4; | | 13 | + // eslint-disable-next-line node-core/no-unescaped-regexp-dot | | 14 | + s.match(/./); // Flatten string. | | 15 | + assert.strictEqual(s.length % 4, 0); | | 16 | + const b = Buffer.allocUnsafe(encodedSize); | | 17 | + b.write(s, 0, encodedSize, 'base64url'); | | 18 | + | | 19 | + let tmp; | | 20 | + | | 21 | + bench.start(); | | 22 | + | | 23 | + for (let i = 0; i < n; i += 1) | | 24 | + tmp = b.base64Write(s, 0, s.length); | | 25 | + | | 26 | + bench.end(n); | | 27 | + | | 28 | + assert.strictEqual(tmp, encodedSize); | | 29 | +} |
Collapse file Copy file name to clipboard +29Lines changed: 29 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +'use strict'; | | 2 | +const common = require('../common.js'); | | 3 | +const assert = require('assert'); | | 4 | + | | 5 | +const bench = common.createBenchmark(main, { | | 6 | + len: [64 * 1024 * 1024], | | 7 | + n: [32], | | 8 | +}, { | | 9 | + test: { len: 256 }, | | 10 | +}); | | 11 | + | | 12 | +function main({ n, len }) { | | 13 | + const b = Buffer.allocUnsafe(len); | | 14 | + let s = ''; | | 15 | + let i; | | 16 | + for (i = 0; i < 256; ++i) s += String.fromCharCode(i); | | 17 | + for (i = 0; i < len; i += 256) b.write(s, i, 256, 'ascii'); | | 18 | + | | 19 | + let tmp; | | 20 | + | | 21 | + bench.start(); | | 22 | + | | 23 | + for (i = 0; i < n; ++i) | | 24 | + tmp = b.toString('base64url'); | | 25 | + | | 26 | + bench.end(n); | | 27 | + | | 28 | + assert.strictEqual(typeof tmp, 'string'); | | 29 | +} |
Collapse file Copy file name to clipboard +29Lines changed: 29 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +'use strict'; | | 2 | + | | 3 | +const common = require('../common.js'); | | 4 | +const assert = require('assert'); | | 5 | + | | 6 | +const bench = common.createBenchmark(main, { | | 7 | + len: [64, 1024], | | 8 | + n: [1e6], | | 9 | +}); | | 10 | + | | 11 | +function main({ len, n }) { | | 12 | + const buf = Buffer.alloc(len); | | 13 | + | | 14 | + for (let i = 0; i < buf.length; i++) | | 15 | + buf[i] = i & 0xff; | | 16 | + | | 17 | + const plain = buf; | | 18 | + | | 19 | + bench.start(); | | 20 | + | | 21 | + let tmp; | | 22 | + | | 23 | + for (let i = 0; i < n; i += 1) | | 24 | + tmp = plain.toString('hex'); | | 25 | + | | 26 | + bench.end(n); | | 27 | + | | 28 | + assert.strictEqual(typeof tmp, 'string'); | | 29 | +} |
Collapse file Copy file name to clipboardExpand all lines: benchmark/buffers/buffer-hex-encode.js +5-1Lines changed: 5 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | 'use strict'; | 2 | 2 |
| 3 | 3 | const common = require('../common.js'); | | 4 | +const assert = require('assert'); | 4 | 5 |
| 5 | 6 | const bench = common.createBenchmark(main, { | 6 | 7 | len: [64, 1024], | @@ -14,11 +15,14 @@ function main({ len, n }) { | 14 | 15 | buf[i] = i & 0xff; | 15 | 16 |
| 16 | 17 | const hex = buf.toString('hex'); | | 18 | + let tmp; | 17 | 19 |
| 18 | 20 | bench.start(); | 19 | 21 |
| 20 | 22 | for (let i = 0; i < n; i += 1) | 21 | | - Buffer.from(hex, 'hex'); | | 23 | + tmp = Buffer.from(hex, 'hex'); | 22 | 24 |
| 23 | 25 | bench.end(n); | | 26 | + | | 27 | + assert.strictEqual(typeof tmp, 'object'); | 24 | 28 | } |
|