diff options
author | Joyee Cheung <joyeec9h3@gmail.com> | 2023-02-11 23:08:41 +0100 |
---|---|---|
committer | Joyee Cheung <joyeec9h3@gmail.com> | 2023-03-07 22:45:40 +0100 |
commit | 044021d341cf108e7eda3e410822dae6b98a8a51 (patch) | |
tree | 979799897c2714a9cf73357a93d96e7bd1c21f76 /benchmark | |
parent | 3b0c047c31eaa65294181c1df7ab49429c477d71 (diff) | |
download | node-new-044021d341cf108e7eda3e410822dae6b98a8a51.tar.gz |
benchmark: stablize encode benchmark
- Increase the number of iteration to 1e6 to reduce flakes. 1e4
can introduce flakes even when comparing the main branch
against itself
- Replace the 1024 * 32 length test with 1024 * 8 since it would
otherwise take too long to complete. Remove the 16 length test
since it's not too different from 32.
- Check the results of the encoding methods at the end.
PR-URL: https://github.com/nodejs/node/pull/46658
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Diffstat (limited to 'benchmark')
-rw-r--r-- | benchmark/util/text-encoder.js | 39 |
1 files changed, 22 insertions, 17 deletions
diff --git a/benchmark/util/text-encoder.js b/benchmark/util/text-encoder.js index 1429710e9c..3150a6fbc8 100644 --- a/benchmark/util/text-encoder.js +++ b/benchmark/util/text-encoder.js @@ -1,10 +1,11 @@ 'use strict'; const common = require('../common.js'); +const assert = require('assert'); const bench = common.createBenchmark(main, { - len: [16, 32, 256, 1024, 1024 * 32], - n: [1e4], + len: [32, 256, 1024, 1024 * 8], + n: [1e6], type: ['one-byte-string', 'two-byte-string', 'ascii'], op: ['encode', 'encodeInto'], }); @@ -26,20 +27,24 @@ function main({ n, op, len, type }) { } const input = base.repeat(len); - const subarray = new Uint8Array(len); - - bench.start(); - switch (op) { - case 'encode': { - for (let i = 0; i < n; i++) - encoder.encode(input); - break; - } - case 'encodeInto': { - for (let i = 0; i < n; i++) - encoder.encodeInto(input, subarray); - break; - } + if (op === 'encode') { + const expected = encoder.encode(input); + let result; + bench.start(); + for (let i = 0; i < n; i++) + result = encoder.encode(input); + bench.end(n); + assert.deepStrictEqual(result, expected); + } else { + const expected = new Uint8Array(len); + const subarray = new Uint8Array(len); + const expectedStats = encoder.encodeInto(input, expected); + let result; + bench.start(); + for (let i = 0; i < n; i++) + result = encoder.encodeInto(input, subarray); + bench.end(n); + assert.deepStrictEqual(subarray, expected); + assert.deepStrictEqual(result, expectedStats); } - bench.end(n); } |