From 3db2990ce73136fe96e78b614cb5719f60e09178 Mon Sep 17 00:00:00 2001 From: Jaco Date: Mon, 20 Jun 2022 10:29:59 +0200 Subject: [PATCH] Change Date.now() to performance.now() (#1551) * Change Date.now() to performance.now() * Adjust --- packages/util-crypto/src/test/performance.ts | 6 +++--- packages/util/src/array/chunk.spec.ts | 4 ++-- packages/util/src/array/shuffle.spec.ts | 4 ++-- packages/util/src/bi/toU8a.spec.ts | 4 ++-- packages/util/src/bn/toU8a.spec.ts | 4 ++-- packages/util/src/compact/fromU8a.spec.ts | 14 +++++++------- packages/util/src/hex/toU8a.spec.ts | 4 ++-- packages/util/src/is/ascii.spec.ts | 4 ++-- packages/util/src/is/codec.spec.ts | 4 ++-- packages/util/src/is/hex.spec.ts | 4 ++-- packages/util/src/is/u8a.spec.ts | 4 ++-- packages/util/src/is/undefined.spec.ts | 4 ++-- packages/util/src/object/property.spec.ts | 6 +++--- packages/util/src/object/spread.spec.ts | 4 ++-- packages/util/src/string/camelCase.spec.ts | 6 +++--- packages/util/src/string/lowerFirst.spec.ts | 4 ++-- packages/util/src/string/upperFirst.spec.ts | 4 ++-- packages/util/src/test/performance.ts | 16 ++++++++-------- packages/util/src/u8a/concat.spec.ts | 8 ++++---- packages/util/src/u8a/empty.spec.ts | 4 ++-- packages/util/src/u8a/eq.spec.ts | 8 ++++---- packages/util/src/u8a/toBigInt.spec.ts | 4 ++-- packages/util/src/u8a/toBn.spec.ts | 8 ++++---- packages/util/src/u8a/toHex.spec.ts | 6 +++--- packages/util/src/u8a/toNumber.spec.ts | 6 +++--- packages/util/src/u8a/toU8a.spec.ts | 8 ++++---- 26 files changed, 76 insertions(+), 76 deletions(-) diff --git a/packages/util-crypto/src/test/performance.ts b/packages/util-crypto/src/test/performance.ts index 640b2d30d..2edf68224 100644 --- a/packages/util-crypto/src/test/performance.ts +++ b/packages/util-crypto/src/test/performance.ts @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 import { arrayRange } from '@polkadot/util'; -import { performance, performanceCmp } from '@polkadot/util/test/performance'; +import { perf, perfCmp } from '@polkadot/util/test/performance'; import { randomAsU8a } from '..'; @@ -11,7 +11,7 @@ type ExecFn = (input: Uint8Array, onlyJs: boolean) => unknown; const GENERATED = arrayRange(256).map(() => [randomAsU8a()]); export function performanceWasm (name: string, count: number, exec: ExecFn, inputs = GENERATED): void { - performanceCmp(name, ['WebAssembly', 'JavaScript'], count, inputs, exec); + perfCmp(name, ['WebAssembly', 'JavaScript'], count, inputs, exec); } -export { performance, performanceCmp }; +export { perf, perfCmp }; diff --git a/packages/util/src/array/chunk.spec.ts b/packages/util/src/array/chunk.spec.ts index 7264ae91b..f00887eba 100644 --- a/packages/util/src/array/chunk.spec.ts +++ b/packages/util/src/array/chunk.spec.ts @@ -1,7 +1,7 @@ // Copyright 2017-2022 @polkadot/util authors & contributors // SPDX-License-Identifier: Apache-2.0 -import { performance } from '../test/performance'; +import { perf } from '../test/performance'; import { arrayChunk, arrayRange } from '.'; describe('arrayChunk', (): void => { @@ -11,5 +11,5 @@ describe('arrayChunk', (): void => { ).toEqual([[1, 2, 3], [4, 5, 6], [7]]); }); - performance('arrayChunk', 200_000, [[arrayRange(500), 50]], arrayChunk); + perf('arrayChunk', 200_000, [[arrayRange(500), 50]], arrayChunk); }); diff --git a/packages/util/src/array/shuffle.spec.ts b/packages/util/src/array/shuffle.spec.ts index d3c83c774..e3feed223 100644 --- a/packages/util/src/array/shuffle.spec.ts +++ b/packages/util/src/array/shuffle.spec.ts @@ -1,7 +1,7 @@ // Copyright 2017-2022 @polkadot/util authors & contributors // SPDX-License-Identifier: Apache-2.0 -import { performance } from '../test/performance'; +import { perf } from '../test/performance'; import { arrayRange, arrayShuffle } from '.'; const ptest = arrayRange(16284); @@ -32,5 +32,5 @@ describe('arrayShuffle', (): void => { ).not.toEqual(JSON.stringify(out)); }); - performance('arrayShuffle', 1000, [[ptest]], arrayShuffle); + perf('arrayShuffle', 1000, [[ptest]], arrayShuffle); }); diff --git a/packages/util/src/bi/toU8a.spec.ts b/packages/util/src/bi/toU8a.spec.ts index 96eb8244c..87fc9e1a0 100644 --- a/packages/util/src/bi/toU8a.spec.ts +++ b/packages/util/src/bi/toU8a.spec.ts @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 import { arrayRange } from '../array'; -import { performance } from '../test/performance'; +import { perf } from '../test/performance'; import { nToU8a } from '.'; const ptest = arrayRange(65536).map((v) => [v]); @@ -56,5 +56,5 @@ describe('nToU8a', (): void => { ).toEqual(new Uint8Array([46, 251, 255, 255])); }); - performance('nToU8a', 250000, ptest, nToU8a); + perf('nToU8a', 250000, ptest, nToU8a); }); diff --git a/packages/util/src/bn/toU8a.spec.ts b/packages/util/src/bn/toU8a.spec.ts index fd952b8a3..e44ef6f60 100644 --- a/packages/util/src/bn/toU8a.spec.ts +++ b/packages/util/src/bn/toU8a.spec.ts @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 import { arrayRange } from '../array'; -import { performance } from '../test/performance'; +import { perf } from '../test/performance'; import { BN, bnToU8a } from '.'; const ptest = arrayRange(65536).map((v) => [v]); @@ -108,5 +108,5 @@ describe('bnToU8a', (): void => { }); }); - performance('bnToU8a', 250000, ptest, bnToU8a); + perf('bnToU8a', 250000, ptest, bnToU8a); }); diff --git a/packages/util/src/compact/fromU8a.spec.ts b/packages/util/src/compact/fromU8a.spec.ts index 9f274de6f..9570cc274 100644 --- a/packages/util/src/compact/fromU8a.spec.ts +++ b/packages/util/src/compact/fromU8a.spec.ts @@ -3,7 +3,7 @@ import { BN } from '../bn/bn'; import { hexToU8a } from '../hex/toU8a'; -import { performance } from '../test/performance'; +import { perf } from '../test/performance'; import { compactFromU8a, compactFromU8aLim } from '.'; describe('compactFromU8a', (): void => { @@ -73,10 +73,10 @@ describe('compactFromU8a', (): void => { ).toEqual('100000000'); }); - performance('compactFromU8a (u8)', 1_000_000, [[new Uint8Array([63 << 2])]], compactFromU8a); - performance('compactFromU8a (u16)', 1_000_000, [[new Uint8Array([0b11111101, 0b00000111])]], compactFromU8a); - performance('compactFromU8a (u32)', 1_000_000, [[new Uint8Array([254, 255, 3, 0])]], compactFromU8a); - performance('compactFromU8aLim (u32)', 1_000_000, [[new Uint8Array([254, 255, 3, 0])]], compactFromU8aLim); - performance('compactFromU8a (u48)', 1_000_000, [[hexToU8a('0x0b00407a10f35a')]], compactFromU8a); - performance('compactFromU8a (u96)', 250_000, [[new Uint8Array([23, 52, 0x40, 0x7a, 0x10, 0xf3, 0x5a, 0, 0, 18])]], compactFromU8a); + perf('compactFromU8a (u8)', 1_000_000, [[new Uint8Array([63 << 2])]], compactFromU8a); + perf('compactFromU8a (u16)', 1_000_000, [[new Uint8Array([0b11111101, 0b00000111])]], compactFromU8a); + perf('compactFromU8a (u32)', 1_000_000, [[new Uint8Array([254, 255, 3, 0])]], compactFromU8a); + perf('compactFromU8aLim (u32)', 1_000_000, [[new Uint8Array([254, 255, 3, 0])]], compactFromU8aLim); + perf('compactFromU8a (u48)', 1_000_000, [[hexToU8a('0x0b00407a10f35a')]], compactFromU8a); + perf('compactFromU8a (u96)', 250_000, [[new Uint8Array([23, 52, 0x40, 0x7a, 0x10, 0xf3, 0x5a, 0, 0, 18])]], compactFromU8a); }); diff --git a/packages/util/src/hex/toU8a.spec.ts b/packages/util/src/hex/toU8a.spec.ts index fad801395..04ac8a5b3 100644 --- a/packages/util/src/hex/toU8a.spec.ts +++ b/packages/util/src/hex/toU8a.spec.ts @@ -1,7 +1,7 @@ // Copyright 2017-2022 @polkadot/util authors & contributors // SPDX-License-Identifier: Apache-2.0 -import { performanceCmp } from '../test/performance'; +import { perfCmp } from '../test/performance'; import { hexToU8a as hexToU8aBuffer } from './toU8aBuffer'; import { hexToU8a } from '.'; @@ -54,7 +54,7 @@ describe('hexToU8a', (): void => { ).toThrow(/hex value to convert/); }); - performanceCmp('hexToU8a', ['hexToU8aBuffer', 'hexToU8a'], 20, [[ptest]], (s: string, isSecond) => + perfCmp('hexToU8a', ['hexToU8aBuffer', 'hexToU8a'], 20, [[ptest]], (s: string, isSecond) => isSecond ? hexToU8a(s) : hexToU8aBuffer(s) diff --git a/packages/util/src/is/ascii.spec.ts b/packages/util/src/is/ascii.spec.ts index 95a4b25b8..fbef307ed 100644 --- a/packages/util/src/is/ascii.spec.ts +++ b/packages/util/src/is/ascii.spec.ts @@ -1,7 +1,7 @@ // Copyright 2017-2022 @polkadot/util authors & contributors // SPDX-License-Identifier: Apache-2.0 -import { performance } from '../test/performance'; +import { perf } from '../test/performance'; import { isAscii } from '.'; describe('isAscii', (): void => { @@ -37,5 +37,5 @@ describe('isAscii', (): void => { expect(isAscii('0x010203')).toEqual(false); }); - performance('isAscii', 100_000, [[[0x31, 0x32, 0x20, 10, 9, 13, 65, 66, 67, 68, 69, 70]]], isAscii); + perf('isAscii', 100_000, [[[0x31, 0x32, 0x20, 10, 9, 13, 65, 66, 67, 68, 69, 70]]], isAscii); }); diff --git a/packages/util/src/is/codec.spec.ts b/packages/util/src/is/codec.spec.ts index 48b627fae..2a9bac8f8 100644 --- a/packages/util/src/is/codec.spec.ts +++ b/packages/util/src/is/codec.spec.ts @@ -1,7 +1,7 @@ // Copyright 2017-2022 @polkadot/util authors & contributors // SPDX-License-Identifier: Apache-2.0 -import { performanceCmp } from '../test/performance'; +import { perfCmp } from '../test/performance'; import { isCodec } from '.'; const ptest = { @@ -47,7 +47,7 @@ describe('isCodec', (): void => { ).toEqual(false); }); - performanceCmp('isCodec', ['isCodec', 'instanceof'], 500_000, [[ptest]], (v: unknown, isSecond) => + perfCmp('isCodec', ['isCodec', 'instanceof'], 500_000, [[ptest]], (v: unknown, isSecond) => isSecond ? !(v instanceof String) : isCodec(v) diff --git a/packages/util/src/is/hex.spec.ts b/packages/util/src/is/hex.spec.ts index b1ba821e4..665862799 100644 --- a/packages/util/src/is/hex.spec.ts +++ b/packages/util/src/is/hex.spec.ts @@ -1,7 +1,7 @@ // Copyright 2017-2022 @polkadot/util authors & contributors // SPDX-License-Identifier: Apache-2.0 -import { performance } from '../test/performance'; +import { perf } from '../test/performance'; import { isHex } from '.'; describe('isHex', (): void => { @@ -71,5 +71,5 @@ describe('isHex', (): void => { ).toEqual(true); }); - performance(`isHex (${(ptest.length - 2) / 2} bytes)`, 5000, [[ptest]], isHex); + perf(`isHex (${(ptest.length - 2) / 2} bytes)`, 5000, [[ptest]], isHex); }); diff --git a/packages/util/src/is/u8a.spec.ts b/packages/util/src/is/u8a.spec.ts index a0a10660a..03084ab1a 100644 --- a/packages/util/src/is/u8a.spec.ts +++ b/packages/util/src/is/u8a.spec.ts @@ -1,7 +1,7 @@ // Copyright 2017-2022 @polkadot/util authors & contributors // SPDX-License-Identifier: Apache-2.0 -import { performance } from '../test/performance'; +import { perf } from '../test/performance'; import { isU8a } from '.'; describe('isU8a', (): void => { @@ -36,5 +36,5 @@ describe('isU8a', (): void => { ).toEqual(true); }); - performance('isU8a', 2_000_000, [[new Uint8Array()]], isU8a); + perf('isU8a', 2_000_000, [[new Uint8Array()]], isU8a); }); diff --git a/packages/util/src/is/undefined.spec.ts b/packages/util/src/is/undefined.spec.ts index b1eb5ed8b..02d99cd4d 100644 --- a/packages/util/src/is/undefined.spec.ts +++ b/packages/util/src/is/undefined.spec.ts @@ -1,7 +1,7 @@ // Copyright 2017-2022 @polkadot/util authors & contributors // SPDX-License-Identifier: Apache-2.0 -import { performance } from '../test/performance'; +import { perf } from '../test/performance'; import { isUndefined } from '.'; describe('isUndefined', (): void => { @@ -17,5 +17,5 @@ describe('isUndefined', (): void => { ).toEqual(false); }); - performance('isUndefined', 10_000_000, [[null]], isUndefined); + perf('isUndefined', 10_000_000, [[null]], isUndefined); }); diff --git a/packages/util/src/object/property.spec.ts b/packages/util/src/object/property.spec.ts index caf6db521..e5ba75f5f 100644 --- a/packages/util/src/object/property.spec.ts +++ b/packages/util/src/object/property.spec.ts @@ -1,7 +1,7 @@ // Copyright 2017-2022 @polkadot/util authors & contributors // SPDX-License-Identifier: Apache-2.0 -import { performance } from '../test/performance'; +import { perf } from '../test/performance'; import { objectProperties, objectProperty } from '.'; describe('objectProperty/objectProperties', (): void => { @@ -142,6 +142,6 @@ describe('objectProperty/objectProperties', (): void => { expect(getter).toHaveBeenCalledWith('b', 1); }); - performance('objectProperties (obj)', 50_000, [[]], () => objectProperties({}, ['foo', 'bar', 'baz'], (k) => k)); - performance('objectProperties (map)', 50_000, [[]], () => objectProperties(new Map(), ['foo', 'bar', 'baz'], (k) => k)); + perf('objectProperties (obj)', 50_000, [[]], () => objectProperties({}, ['foo', 'bar', 'baz'], (k) => k)); + perf('objectProperties (map)', 50_000, [[]], () => objectProperties(new Map(), ['foo', 'bar', 'baz'], (k) => k)); }); diff --git a/packages/util/src/object/spread.spec.ts b/packages/util/src/object/spread.spec.ts index e18e8f939..c6f3a08be 100644 --- a/packages/util/src/object/spread.spec.ts +++ b/packages/util/src/object/spread.spec.ts @@ -1,7 +1,7 @@ // Copyright 2017-2022 @polkadot/util authors & contributors // SPDX-License-Identifier: Apache-2.0 -import { performance } from '../test/performance'; +import { perf } from '../test/performance'; import { objectSpread } from '.'; describe('objectSpread', (): void => { @@ -17,5 +17,5 @@ describe('objectSpread', (): void => { ).toEqual({ a: 2, b: 2, c: { d: 3, e: 4 } }); }); - performance('objectSpread', 500_000, [[]], () => objectSpread({}, { a: 1, b: 2, c: 3 }, { d: 4, e: 7, f: 6 })); + perf('objectSpread', 500_000, [[]], () => objectSpread({}, { a: 1, b: 2, c: 3 }, { d: 4, e: 7, f: 6 })); }); diff --git a/packages/util/src/string/camelCase.spec.ts b/packages/util/src/string/camelCase.spec.ts index 6467e326f..eebc041b5 100644 --- a/packages/util/src/string/camelCase.spec.ts +++ b/packages/util/src/string/camelCase.spec.ts @@ -4,7 +4,7 @@ import { getRandomValues } from '@polkadot/x-randomvalues'; import { arrayRange } from '../array'; -import { performance } from '../test/performance'; +import { perf } from '../test/performance'; import { stringCamelCase, stringUpperFirst } from '.'; const SEPS = [' ', '_', '-', '.', ',']; @@ -112,6 +112,6 @@ describe('stringCamelCase', (): void => { ).toEqual('aBCDef'); }); - performance('stringCamelCase (random)', 100_000, randomWords, stringCamelCase); - performance('stringCamelCase (NFTOrder)', 100_000, [['NFTOrder']], stringCamelCase); + perf('stringCamelCase (random)', 100_000, randomWords, stringCamelCase); + perf('stringCamelCase (NFTOrder)', 100_000, [['NFTOrder']], stringCamelCase); }); diff --git a/packages/util/src/string/lowerFirst.spec.ts b/packages/util/src/string/lowerFirst.spec.ts index a7ef11d32..a8f301738 100644 --- a/packages/util/src/string/lowerFirst.spec.ts +++ b/packages/util/src/string/lowerFirst.spec.ts @@ -1,7 +1,7 @@ // Copyright 2017-2022 @polkadot/util authors & contributors // SPDX-License-Identifier: Apache-2.0 -import { performance } from '../test/performance'; +import { perf } from '../test/performance'; import { stringLowerFirst } from '.'; describe('stringLowerFirst', (): void => { @@ -35,5 +35,5 @@ describe('stringLowerFirst', (): void => { ).toBe(''); }); - performance('stringLowerFirst', 1_000_000, [['HelloWorldSomething']], stringLowerFirst); + perf('stringLowerFirst', 1_000_000, [['HelloWorldSomething']], stringLowerFirst); }); diff --git a/packages/util/src/string/upperFirst.spec.ts b/packages/util/src/string/upperFirst.spec.ts index c707f7ce8..f5e8e3683 100644 --- a/packages/util/src/string/upperFirst.spec.ts +++ b/packages/util/src/string/upperFirst.spec.ts @@ -1,7 +1,7 @@ // Copyright 2017-2022 @polkadot/util authors & contributors // SPDX-License-Identifier: Apache-2.0 -import { performance } from '../test/performance'; +import { perf } from '../test/performance'; import { stringUpperFirst } from '.'; describe('stringUpperFirst', (): void => { @@ -35,5 +35,5 @@ describe('stringUpperFirst', (): void => { ).toBe(''); }); - performance('stringUpperFirst', 1_000_000, [['helloWorldSomething']], stringUpperFirst); + perf('stringUpperFirst', 1_000_000, [['helloWorldSomething']], stringUpperFirst); }); diff --git a/packages/util/src/test/performance.ts b/packages/util/src/test/performance.ts index c5ae645ed..56d82f915 100644 --- a/packages/util/src/test/performance.ts +++ b/packages/util/src/test/performance.ts @@ -1,4 +1,4 @@ -// Copyright 2017-2022 @polkadot/util-crypto authors & contributors +// Copyright 2017-2022 @polkadot/util authors & contributors // SPDX-License-Identifier: Apache-2.0 import { formatDecimal, formatNumber } from '..'; @@ -10,7 +10,7 @@ const NUM_PAD = 16; const PRE_PAD = 32; function loop (count: number, inputs: unknown[][], exec: ExecFn): [number, unknown[]] { - const start = Date.now(); + const start = performance.now(); const results = new Array(inputs.length); for (let i = 0; i < count; i++) { @@ -21,7 +21,7 @@ function loop (count: number, inputs: unknown[][], exec: ExecFn): [number, unkno } } - return [Date.now() - start, results]; + return [performance.now() - start, results]; } export function formatFixed (value: number): string { @@ -39,19 +39,19 @@ ${formatFixed(ops).padStart(NUM_PAD + PRE_PAD + 1)} ops/s ${formatFixed(micro).padStart(NUM_PAD + PRE_PAD + 1)} μs/op`; } -export function performance (name: string, count: number, inputs: unknown[][], exec: ExecFn): void { +export function perf (name: string, count: number, inputs: unknown[][], exec: ExecFn): void { it(`performance: ${name}`, (): void => { const [time] = loop(count, inputs, exec); console.log(` performance run for ${name} completed with ${formatNumber(count)} iterations. -${`${name}:`.padStart(PRE_PAD)} ${time.toString().padStart(NUM_PAD)} ms${formatOps(count, time)} +${`${name}:`.padStart(PRE_PAD)} ${time.toFixed(2).padStart(NUM_PAD)} ms${formatOps(count, time)} `); }); } -export function performanceCmp (name: string, [first, second]: [string, string], count: number, inputs: unknown[][], exec: ExecFn): void { +export function perfCmp (name: string, [first, second]: [string, string], count: number, inputs: unknown[][], exec: ExecFn): void { it(`performance: ${name}`, (): void => { const pa = inputs.map((values) => [...values, false]); const pb = inputs.map((values) => [...values, true]); @@ -61,9 +61,9 @@ export function performanceCmp (name: string, [first, second]: [string, string], console.log(` performance run for ${name} completed with ${formatNumber(count)} iterations. -${`${first}:`.padStart(PRE_PAD)} ${ta.toString().padStart(NUM_PAD)} ms ${ta < tb ? '(fastest)' : `(slowest, ${(ta / tb).toFixed(2)}x)`}${formatOps(count, ta)} +${`${first}:`.padStart(PRE_PAD)} ${ta.toFixed(2).padStart(NUM_PAD)} ms ${ta < tb ? '(fastest)' : `(slowest, ${(ta / tb).toFixed(2)}x)`}${formatOps(count, ta)} -${`${second}:`.padStart(PRE_PAD)} ${tb.toString().padStart(NUM_PAD)} ms ${ta > tb ? '(fastest)' : `(slowest, ${(tb / ta).toFixed(2)}x)`}${formatOps(count, tb)} +${`${second}:`.padStart(PRE_PAD)} ${tb.toFixed(2).padStart(NUM_PAD)} ms ${ta > tb ? '(fastest)' : `(slowest, ${(tb / ta).toFixed(2)}x)`}${formatOps(count, tb)} `); const unmatched = ra.filter((r, i) => diff --git a/packages/util/src/u8a/concat.spec.ts b/packages/util/src/u8a/concat.spec.ts index ed3ec6a96..7966c2c72 100644 --- a/packages/util/src/u8a/concat.spec.ts +++ b/packages/util/src/u8a/concat.spec.ts @@ -4,7 +4,7 @@ import { getRandomValues } from '@polkadot/x-randomvalues'; import { arrayRange } from '../array'; -import { performance } from '../test/performance'; +import { perf } from '../test/performance'; import { u8aConcat, u8aConcatStrict } from '.'; const ptest = arrayRange(10).map(() => getRandomValues(new Uint8Array(32))); @@ -34,7 +34,7 @@ describe('u8aConcat', (): void => { ); }); - performance('u8aConcat', 10000, [[ptest]], u8aConcat); - performance('u8aConcatStrict', 10000, [[[ptest]]], u8aConcatStrict); - performance('u8aConcatStrict (len)', 10000, [[[ptest], 320]], u8aConcatStrict); + perf('u8aConcat', 10000, [[ptest]], u8aConcat); + perf('u8aConcatStrict', 10000, [[[ptest]]], u8aConcatStrict); + perf('u8aConcatStrict (len)', 10000, [[[ptest], 320]], u8aConcatStrict); }); diff --git a/packages/util/src/u8a/empty.spec.ts b/packages/util/src/u8a/empty.spec.ts index 2c04093a8..739f4f2ae 100644 --- a/packages/util/src/u8a/empty.spec.ts +++ b/packages/util/src/u8a/empty.spec.ts @@ -1,7 +1,7 @@ // Copyright 2017-2022 @polkadot/util authors & contributors // SPDX-License-Identifier: Apache-2.0 -import { performance } from '../test/performance'; +import { perf } from '../test/performance'; import { u8aEmpty } from '.'; const ztest = new Uint8Array(32); @@ -25,5 +25,5 @@ describe('u8aEmpty', (): void => { ).toEqual(false); }); - performance('u8aEmpty (32 cmp)', 1000000, [[ztest]], u8aEmpty); + perf('u8aEmpty (32 cmp)', 1000000, [[ztest]], u8aEmpty); }); diff --git a/packages/util/src/u8a/eq.spec.ts b/packages/util/src/u8a/eq.spec.ts index 53240ad7e..211db0f27 100644 --- a/packages/util/src/u8a/eq.spec.ts +++ b/packages/util/src/u8a/eq.spec.ts @@ -1,7 +1,7 @@ // Copyright 2017-2022 @polkadot/util authors & contributors // SPDX-License-Identifier: Apache-2.0 -import { performance } from '../test/performance'; +import { perf } from '../test/performance'; import { u8aEq } from '.'; const ltest = new Uint8Array(32768); @@ -105,7 +105,7 @@ describe('u8aEq', (): void => { ).toEqual(true); }); - performance('u8aEq (64 cmp)', 200_000, [[ztest, ztest]], u8aEq); - performance('u8aEq (256 cmp)', 200_000, [[stest, stest]], u8aEq); - performance('u8aEq (32k cmp)', 10_000, [[ltest, ltest]], u8aEq); + perf('u8aEq (64 cmp)', 200_000, [[ztest, ztest]], u8aEq); + perf('u8aEq (256 cmp)', 200_000, [[stest, stest]], u8aEq); + perf('u8aEq (32k cmp)', 10_000, [[ltest, ltest]], u8aEq); }); diff --git a/packages/util/src/u8a/toBigInt.spec.ts b/packages/util/src/u8a/toBigInt.spec.ts index 6be9ad183..5ffec9dd1 100644 --- a/packages/util/src/u8a/toBigInt.spec.ts +++ b/packages/util/src/u8a/toBigInt.spec.ts @@ -1,7 +1,7 @@ // Copyright 2017-2022 @polkadot/util authors & contributors // SPDX-License-Identifier: Apache-2.0 -import { performance } from '../test/performance'; +import { perf } from '../test/performance'; import { u8aToBigInt } from '.'; describe('u8aToBigInt', (): void => { @@ -58,5 +58,5 @@ describe('u8aToBigInt', (): void => { ).toEqual(-1234n); }); - performance('u8aToBigInt', 500000, [[new Uint8Array([0x68, 0x65, 0x6c, 0x6c])]], u8aToBigInt); + perf('u8aToBigInt', 500000, [[new Uint8Array([0x68, 0x65, 0x6c, 0x6c])]], u8aToBigInt); }); diff --git a/packages/util/src/u8a/toBn.spec.ts b/packages/util/src/u8a/toBn.spec.ts index 4d21a2a2f..8449c354a 100644 --- a/packages/util/src/u8a/toBn.spec.ts +++ b/packages/util/src/u8a/toBn.spec.ts @@ -1,7 +1,7 @@ // Copyright 2017-2022 @polkadot/util authors & contributors // SPDX-License-Identifier: Apache-2.0 -import { performance } from '../test/performance'; +import { perf } from '../test/performance'; import { u8aToBn } from '.'; describe('u8aToBn', (): void => { @@ -299,7 +299,7 @@ describe('u8aToBn', (): void => { ).toBe(true); }); - performance('u8aToBn (u32)', 1_000_000, [[new Uint8Array([0x68, 0x65, 0x6c, 0x6c])]], u8aToBn); - performance('u8aToBn (i32)', 1_000_000, [[new Uint8Array([0x68, 0x65, 0x6c, 0x6c])]], (v: Uint8Array) => u8aToBn(v, { isNegative: true })); - performance('u8aToBn (u64)', 500_000, [[new Uint8Array([0x68, 0x65, 0x6c, 0x6c, 0x68, 0x65, 0x6c, 0x6c])]], u8aToBn); + perf('u8aToBn (u32)', 1_000_000, [[new Uint8Array([0x68, 0x65, 0x6c, 0x6c])]], u8aToBn); + perf('u8aToBn (i32)', 1_000_000, [[new Uint8Array([0x68, 0x65, 0x6c, 0x6c])]], (v: Uint8Array) => u8aToBn(v, { isNegative: true })); + perf('u8aToBn (u64)', 500_000, [[new Uint8Array([0x68, 0x65, 0x6c, 0x6c, 0x68, 0x65, 0x6c, 0x6c])]], u8aToBn); }); diff --git a/packages/util/src/u8a/toHex.spec.ts b/packages/util/src/u8a/toHex.spec.ts index 6085d9e40..3d342e8a0 100644 --- a/packages/util/src/u8a/toHex.spec.ts +++ b/packages/util/src/u8a/toHex.spec.ts @@ -1,7 +1,7 @@ // Copyright 2017-2022 @polkadot/util authors & contributors // SPDX-License-Identifier: Apache-2.0 -import { performanceCmp } from '../test/performance'; +import { perfCmp } from '../test/performance'; import { u8aToHex as u8aToHexBuffer } from './toHexBuffer'; import { u8aToHex } from '.'; @@ -78,12 +78,12 @@ describe('u8aToHex', (): void => { ).toEqual('0x68656c6c6f20776f726c64'); }); - performanceCmp('u8aToHex (32k)', ['u8aToHexBuffer', 'u8aToHex'], 2000, [[ptest32k]], (s: Uint8Array, isSecond) => + perfCmp('u8aToHex (32k)', ['u8aToHexBuffer', 'u8aToHex'], 2000, [[ptest32k]], (s: Uint8Array, isSecond) => isSecond ? u8aToHex(s) : u8aToHexBuffer(s) ); - performanceCmp('u8aToHex (128)', ['u8aToHexBuffer', 'u8aToHex'], 100000, [[ptest256]], (s: Uint8Array, isSecond) => + perfCmp('u8aToHex (128)', ['u8aToHexBuffer', 'u8aToHex'], 100000, [[ptest256]], (s: Uint8Array, isSecond) => isSecond ? u8aToHex(s) : u8aToHexBuffer(s) diff --git a/packages/util/src/u8a/toNumber.spec.ts b/packages/util/src/u8a/toNumber.spec.ts index 43e7c6043..d6d613701 100644 --- a/packages/util/src/u8a/toNumber.spec.ts +++ b/packages/util/src/u8a/toNumber.spec.ts @@ -1,7 +1,7 @@ // Copyright 2017-2022 @polkadot/util authors & contributors // SPDX-License-Identifier: Apache-2.0 -import { performance } from '../test/performance'; +import { perf } from '../test/performance'; import { u8aToNumber } from '.'; describe('u8aToNumber', (): void => { @@ -130,6 +130,6 @@ describe('u8aToNumber', (): void => { }); }); - performance('u8aToNumber (u32)', 1_000_000, [[new Uint8Array([0x68, 0x65, 0x6c, 0x6c])]], u8aToNumber); - performance('u8aToNumber (i32)', 1_000_000, [[new Uint8Array([0x68, 0x65, 0x6c, 0x6c])]], (v: Uint8Array) => u8aToNumber(v, { isNegative: true })); + perf('u8aToNumber (u32)', 1_000_000, [[new Uint8Array([0x68, 0x65, 0x6c, 0x6c])]], u8aToNumber); + perf('u8aToNumber (i32)', 1_000_000, [[new Uint8Array([0x68, 0x65, 0x6c, 0x6c])]], (v: Uint8Array) => u8aToNumber(v, { isNegative: true })); }); diff --git a/packages/util/src/u8a/toU8a.spec.ts b/packages/util/src/u8a/toU8a.spec.ts index 100a2203d..3fbcdde60 100644 --- a/packages/util/src/u8a/toU8a.spec.ts +++ b/packages/util/src/u8a/toU8a.spec.ts @@ -1,7 +1,7 @@ // Copyright 2017-2022 @polkadot/util authors & contributors // SPDX-License-Identifier: Apache-2.0 -import { performance } from '../test/performance'; +import { perf } from '../test/performance'; import { u8aToU8a } from '.'; describe('u8aToU8a', (): void => { @@ -70,7 +70,7 @@ describe('u8aToU8a', (): void => { ).toEqual(new Uint8Array([49, 50, 51])); }); - performance('u8aToU8a (hex)', 250_000, [['0x1234']], u8aToU8a); - performance('u8aToU8a (str)', 250_000, [['test']], u8aToU8a); - performance('u8aToU8a (u8a)', 1_000_000, [[new Uint8Array()]], u8aToU8a); + perf('u8aToU8a (hex)', 250_000, [['0x1234']], u8aToU8a); + perf('u8aToU8a (str)', 250_000, [['test']], u8aToU8a); + perf('u8aToU8a (u8a)', 1_000_000, [[new Uint8Array()]], u8aToU8a); });