Adjust and enable old perfromance tests (#1233)
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
// Copyright 2017-2021 @polkadot/util-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { arrayRange } from '@polkadot/util';
|
||||
import { arrayRange, formatNumber } from '@polkadot/util';
|
||||
import { randomAsU8a } from '@polkadot/util-crypto';
|
||||
|
||||
import { formatOps, performanceJs } from '../../util/test/performance';
|
||||
@@ -31,7 +31,7 @@ export function performanceWasm (name: string, count: number, exec: ExecFn): voi
|
||||
const [js, rjs] = loop(count, true, exec);
|
||||
|
||||
console.log(`
|
||||
performance run for ${name} completed with ${count} iterations.
|
||||
performance run for ${name} completed with ${formatNumber(count)} iterations.
|
||||
|
||||
${'WebAssembly:'.padStart(19)} ${ws.toString().padStart(15)} ms ${ws < js ? '(fastest)' : `(slowest, ${(ws / js).toFixed(2)}x)`}${formatOps(count, ws)}
|
||||
|
||||
|
||||
@@ -1,9 +1,16 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { performanceJs } from '../../test/performance';
|
||||
import { U16_TO_HEX } from './alphabet';
|
||||
import { hexToU8a } from '.';
|
||||
|
||||
let ptest = '0x';
|
||||
|
||||
for (let i = 0; i < 640 * 1024; i++) {
|
||||
ptest += U16_TO_HEX[i % (256 * 256)];
|
||||
}
|
||||
|
||||
describe('hexToU8a', (): void => {
|
||||
it('returns an empty Uint8Array when null provided', (): void => {
|
||||
expect(
|
||||
@@ -47,19 +54,5 @@ describe('hexToU8a', (): void => {
|
||||
).toThrow(/hex value to convert/);
|
||||
});
|
||||
|
||||
it.skip('performance', (): void => {
|
||||
let a = '0x';
|
||||
|
||||
for (let i = 0; i < 640000; i++) {
|
||||
a += U16_TO_HEX[i % (256 * 256)];
|
||||
}
|
||||
|
||||
console.time('hexToU8a:performance');
|
||||
|
||||
for (let i = 0; i < 64; i++) {
|
||||
hexToU8a(a);
|
||||
}
|
||||
|
||||
console.timeEnd('hexToU8a:performance');
|
||||
});
|
||||
performanceJs('hexToU8a (640k input)', 10, [[ptest]], hexToU8a);
|
||||
});
|
||||
|
||||
@@ -1,9 +1,16 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { performanceJs } from '../../test/performance';
|
||||
import { U16_TO_HEX } from './alphabet';
|
||||
import { hexToU8a } from './toU8aBuffer';
|
||||
|
||||
let ptest = '0x';
|
||||
|
||||
for (let i = 0; i < 640 * 1024; i++) {
|
||||
ptest += U16_TO_HEX[i % (256 * 256)];
|
||||
}
|
||||
|
||||
describe('hexToU8a', (): void => {
|
||||
it('returns an empty Uint8Array when null provided', (): void => {
|
||||
expect(
|
||||
@@ -41,19 +48,5 @@ describe('hexToU8a', (): void => {
|
||||
).toThrow(/hex value to convert/);
|
||||
});
|
||||
|
||||
it.skip('performance', (): void => {
|
||||
let a = '0x';
|
||||
|
||||
for (let i = 0; i < 640000; i++) {
|
||||
a += U16_TO_HEX[i % (256 * 256)];
|
||||
}
|
||||
|
||||
console.time('hexToU8a:performance');
|
||||
|
||||
for (let i = 0; i < 64; i++) {
|
||||
hexToU8a(a);
|
||||
}
|
||||
|
||||
console.timeEnd('hexToU8a:performance');
|
||||
});
|
||||
performanceJs('hexToU8a (Node Buffer, 640k input)', 10, [[ptest]], hexToU8a);
|
||||
});
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { performanceJs } from '../../test/performance';
|
||||
import { isHex } from '.';
|
||||
|
||||
describe('isHex', (): void => {
|
||||
const test = '1234abcd';
|
||||
const ptest = '0x1234adbcdef5798351773526352876adbcdef2358735adbcdef2623587adbcdef11234adbcdef5798351773526352876adbcdef2358735adbcdef2623587adbcdef11234adbcdef5798351773526352876adbcdef2358735adbcdef2623587adbcdef11234adbcdef5798351773526352876adbcdef2358735adbcdef2623587adbcdef1';
|
||||
|
||||
it('returns true on 0x hex values', (): void => {
|
||||
expect(
|
||||
@@ -69,15 +71,5 @@ describe('isHex', (): void => {
|
||||
).toEqual(true);
|
||||
});
|
||||
|
||||
it.skip('performance', (): void => {
|
||||
const test = '0x1234adbcdef5798351773526352876adbcdef2358735adbcdef2623587adbcdef11234adbcdef5798351773526352876adbcdef2358735adbcdef2623587adbcdef11234adbcdef5798351773526352876adbcdef2358735adbcdef2623587adbcdef11234adbcdef5798351773526352876adbcdef2358735adbcdef2623587adbcdef1';
|
||||
|
||||
console.time('performance:isHex');
|
||||
|
||||
for (let i = 0; i < 512000; i++) {
|
||||
isHex(test);
|
||||
}
|
||||
|
||||
console.timeEnd('performance:isHex');
|
||||
});
|
||||
performanceJs('isHex (1024-bit)', 1000000, [[ptest]], isHex);
|
||||
});
|
||||
|
||||
@@ -1,8 +1,15 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { performanceJs } from '../../test/performance';
|
||||
import { u8aEq } from '.';
|
||||
|
||||
const ptest = new Uint8Array(32768);
|
||||
|
||||
for (let i = 0; i < ptest.length; i++) {
|
||||
ptest[i] = i % 256;
|
||||
}
|
||||
|
||||
describe('u8aEq', (): void => {
|
||||
it('returns false when the lengths do not match', (): void => {
|
||||
expect(
|
||||
@@ -88,19 +95,5 @@ describe('u8aEq', (): void => {
|
||||
).toEqual(true);
|
||||
});
|
||||
|
||||
it.skip('performance', (): void => {
|
||||
const a = new Uint8Array(32768);
|
||||
|
||||
for (let i = 0; i < a.length; i++) {
|
||||
a[i] = i % 256;
|
||||
}
|
||||
|
||||
console.time('u8aEq:performance');
|
||||
|
||||
for (let i = 0; i < 65536; i++) {
|
||||
u8aEq(a, a);
|
||||
}
|
||||
|
||||
console.timeEnd('u8aEq:performance');
|
||||
});
|
||||
performanceJs('u8aEq (32k cmp)', 50000, [[ptest, ptest]], u8aEq);
|
||||
});
|
||||
|
||||
@@ -1,8 +1,15 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { performanceJs } from '../../test/performance';
|
||||
import { u8aToHex } from '.';
|
||||
|
||||
const ptest = new Uint8Array(32768);
|
||||
|
||||
for (let i = 0; i < ptest.length; i++) {
|
||||
ptest[i] = i % 256;
|
||||
}
|
||||
|
||||
describe('u8aToHex', (): void => {
|
||||
it('returns empty as 0x', (): void => {
|
||||
expect(
|
||||
@@ -58,19 +65,5 @@ describe('u8aToHex', (): void => {
|
||||
).toEqual('0x8000…0c0d');
|
||||
});
|
||||
|
||||
it.skip('performance', (): void => {
|
||||
const a = new Uint8Array(32768);
|
||||
|
||||
for (let i = 0; i < a.length; i++) {
|
||||
a[i] = i % 256;
|
||||
}
|
||||
|
||||
console.time('u8aToHex:performance');
|
||||
|
||||
for (let i = 0; i < 65536; i++) {
|
||||
u8aToHex(a);
|
||||
}
|
||||
|
||||
console.timeEnd('u8aToHex:performance');
|
||||
});
|
||||
performanceJs('u8aToHex (32k input)', 2000, [[ptest]], u8aToHex);
|
||||
});
|
||||
|
||||
@@ -1,8 +1,15 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { performanceJs } from '../../test/performance';
|
||||
import { u8aToHex } from './toHexBuffer';
|
||||
|
||||
const ptest = new Uint8Array(32768);
|
||||
|
||||
for (let i = 0; i < ptest.length; i++) {
|
||||
ptest[i] = i % 256;
|
||||
}
|
||||
|
||||
describe('u8aToHex', (): void => {
|
||||
it('returns empty as 0x', (): void => {
|
||||
expect(
|
||||
@@ -58,19 +65,5 @@ describe('u8aToHex', (): void => {
|
||||
).toEqual('0x8000…0c0d');
|
||||
});
|
||||
|
||||
it.skip('performance', (): void => {
|
||||
const a = new Uint8Array(32768);
|
||||
|
||||
for (let i = 0; i < a.length; i++) {
|
||||
a[i] = i % 256;
|
||||
}
|
||||
|
||||
console.time('u8aToHex:performance');
|
||||
|
||||
for (let i = 0; i < 65536; i++) {
|
||||
u8aToHex(a);
|
||||
}
|
||||
|
||||
console.timeEnd('u8aToHex:performance');
|
||||
});
|
||||
performanceJs('u8aToHex (Node Buffer, 32k input)', 2000, [[ptest]], u8aToHex);
|
||||
});
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright 2017-2021 @polkadot/util-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { formatDecimal } from '@polkadot/util';
|
||||
import { formatDecimal, formatNumber } from '@polkadot/util';
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
type ExecFn = (...params: any[]) => unknown;
|
||||
@@ -36,7 +36,7 @@ export function performanceJs (name: string, count: number, inputs: unknown[][],
|
||||
const time = loop(count, inputs, exec);
|
||||
|
||||
console.log(`
|
||||
performance run for ${name} completed with ${count} iterations.
|
||||
performance run for ${name} completed with ${formatNumber(count)} iterations.
|
||||
|
||||
${'JavaScript:'.padStart(19)} ${time.toString().padStart(15)} ms${formatOps(count, time)}
|
||||
`);
|
||||
|
||||
Reference in New Issue
Block a user