Performance test adjustments (#1239)

* Performance test adjustments

* testing

* adjust

* alphabet

* Adjust
This commit is contained in:
Jaco
2021-11-25 09:16:01 +02:00
committed by GitHub
parent b05abf869a
commit 0ee4bc81f5
6 changed files with 17 additions and 5 deletions
+6
View File
@@ -1,8 +1,12 @@
// Copyright 2017-2021 @polkadot/util authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { performance } from '../../test/performance';
import { arrayRange } from '../array';
import { biToU8a } from '.';
const ptest = arrayRange(65536).map((v) => [v]);
describe('biToU8a', (): void => {
it('converts null values to 0x00', (): void => {
expect(
@@ -51,4 +55,6 @@ describe('biToU8a', (): void => {
biToU8a(-1234n, { bitLength: 32, isNegative: true })
).toEqual(new Uint8Array([46, 251, 255, 255]));
});
performance('biToU8a', 250000, ptest, biToU8a);
});
+6
View File
@@ -1,8 +1,12 @@
// Copyright 2017-2021 @polkadot/util authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { performance } from '../../test/performance';
import { arrayRange } from '../array';
import { BN, bnToU8a } from '.';
const ptest = arrayRange(65536).map((v) => [v]);
describe('bnToU8a', (): void => {
it('converts null values to 0x00', (): void => {
expect(
@@ -59,4 +63,6 @@ describe('bnToU8a', (): void => {
bnToU8a(new BN(1234), { bitLength: 32, isLe: false })
);
});
performance('bnToU8a', 250000, ptest, bnToU8a);
});
+1 -1
View File
@@ -17,7 +17,7 @@ for (let n = 0; n < 256; n++) {
for (let i = 0; i < 256; i++) {
for (let j = 0; j < 256; j++) {
const hex = U8_TO_HEX[i] + U8_TO_HEX[j];
const n = (i * 256) + j;
const n = (i << 8) | j;
U16_TO_HEX[n] = hex;
HEX_TO_U16[hex] = n;
+2 -2
View File
@@ -8,7 +8,7 @@ import { hexToU8a } from '.';
let ptest = '0x';
for (let i = 0; i < 640 * 1024; i++) {
for (let i = 0; i < 500000; i++) {
ptest += U16_TO_HEX[i % (256 * 256)];
}
@@ -55,7 +55,7 @@ describe('hexToU8a', (): void => {
).toThrow(/hex value to convert/);
});
performanceCmp('hexToU8a (640k input)', ['Node + Buffer', 'Uint8Array'], 10, [[ptest]], (s: string, isSecond) =>
performanceCmp('hexToU8a', ['hexToU8aBuffer', 'hexToU8a'], 10, [[ptest]], (s: string, isSecond) =>
isSecond
? hexToU8a(s)
: hexToU8aBuffer(s)
+1 -1
View File
@@ -66,7 +66,7 @@ describe('u8aToHex', (): void => {
).toEqual('0x8000…0c0d');
});
performanceCmp('u8aToHex (32k input)', ['Node + Buffer', 'Uint8Array'], 2000, [[ptest]], (s: Uint8Array, isSecond) =>
performanceCmp('u8aToHex', ['u8aToHexBuffer', 'u8aToHex'], 2000, [[ptest]], (s: Uint8Array, isSecond) =>
isSecond
? u8aToHex(s)
: u8aToHexBuffer(s)
+1 -1
View File
@@ -43,7 +43,7 @@ export function performance (name: string, count: number, inputs: unknown[][], e
console.log(`
performance run for ${name} completed with ${formatNumber(count)} iterations.
${'JavaScript:'.padStart(19)} ${time.toString().padStart(15)} ms${formatOps(count, time)}
${`${name}:`.padStart(19)} ${time.toString().padStart(15)} ms${formatOps(count, time)}
`);
});
}