Change Date.now() to performance.now() (#1551)
* Change Date.now() to performance.now() * Adjust
This commit is contained in:
@@ -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);
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
@@ -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));
|
||||
});
|
||||
|
||||
@@ -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 }));
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
@@ -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<unknown>(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) =>
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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 }));
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user