Adjust with tsconfig references (#1317)

* Adjust with tsconfig references

* tabs -> spaces

* Adjust

* Cleanup spacing

* Adjust

* eslint-specific config

* Bump deps

* Bumps

* Adjust

* Update tests
This commit is contained in:
Jaco
2021-12-14 08:23:16 +02:00
committed by GitHub
parent fdd32df12f
commit feae08fc0f
68 changed files with 1020 additions and 816 deletions
+1 -1
View File
@@ -1,8 +1,8 @@
// Copyright 2017-2021 @polkadot/util authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { performance } from '../../test/performance';
import { arrayRange } from '../array';
import { performance } from '../test/performance';
import { nToU8a } from '.';
const ptest = arrayRange(65536).map((v) => [v]);
+1 -1
View File
@@ -1,8 +1,8 @@
// Copyright 2017-2021 @polkadot/util authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { performance } from '../../test/performance';
import { arrayRange } from '../array';
import { performance } from '../test/performance';
import { BN, bnToU8a } from '.';
const ptest = arrayRange(65536).map((v) => [v]);
+1 -1
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2021 @polkadot/util authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { performanceCmp } from '../../test/performance';
import { performanceCmp } from '../test/performance';
import { U16_TO_HEX } from './alphabet';
import { hexToU8a as hexToU8aBuffer } from './toU8aBuffer';
import { hexToU8a } from '.';
+1 -1
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2021 @polkadot/util authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { performance } from '../../test/performance';
import { performance } from '../test/performance';
import { isHex } from '.';
describe('isHex', (): void => {
+9 -3
View File
@@ -1,14 +1,20 @@
// Copyright 2017-2021 @polkadot/util authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { randomAsNumber } from '@polkadot/util-crypto';
import words from '@polkadot/util-crypto/mnemonic/bip39-en';
import { getRandomValues } from '@polkadot/x-randomvalues';
import { performance } from '../../test/performance';
import { arrayRange } from '../array';
import { performance } from '../test/performance';
import { stringCamelCase, stringUpperFirst } from '.';
const SEPS = [' ', '_', '-', '.', ','];
const words = 'bring|brisk|broccoli|broken|bronze|broom|brother|brown|brush|bubble|buddy|budget|buffalo|build|bulb|bulk|bullet|bundle|bunker|burden'.split('|');
function randomAsNumber (): number {
const rand = getRandomValues(new Uint8Array(4));
return rand.reduce((v, t) => (v * t) + v, 0);
}
const randomWords = arrayRange(256).map((): [string] => {
let result = '';
+72
View File
@@ -0,0 +1,72 @@
// Copyright 2017-2021 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { formatDecimal, formatNumber } from '..';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
type ExecFn = (...params: any[]) => unknown;
function loop (count: number, inputs: unknown[][], exec: ExecFn): [number, unknown[]] {
const start = Date.now();
const results = new Array<unknown>(inputs.length);
for (let i = 0; i < count; i++) {
const result = exec(...inputs[i % inputs.length]);
if (i < inputs.length) {
results[i] = result;
}
}
return [Date.now() - start, results];
}
export function formatFixed (value: number): string {
const [a, b] = value.toFixed(2).split('.');
return [formatDecimal(a), b].join('.');
}
export function formatOps (count: number, time: number): string {
const micro = (time * 1000) / count;
const ops = 1_000_000 / micro;
return `
${formatFixed(ops).padStart(15 + 20)} ops/s
${formatFixed(micro).padStart(15 + 20)} μs/op`;
}
export function performance (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(19)} ${time.toString().padStart(15)} ms${formatOps(count, time)}
`);
});
}
export function performanceCmp (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]);
const [ta, ra] = loop(count, pa, exec);
const [tb, rb] = loop(count, pb, exec);
console.log(`
performance run for ${name} completed with ${formatNumber(count)} iterations.
${`${first}:`.padStart(19)} ${ta.toString().padStart(15)} ms ${ta < tb ? '(fastest)' : `(slowest, ${(ta / tb).toFixed(2)}x)`}${formatOps(count, ta)}
${`${second}:`.padStart(19)} ${tb.toString().padStart(15)} ms ${ta > tb ? '(fastest)' : `(slowest, ${(tb / ta).toFixed(2)}x)`}${formatOps(count, tb)}
`);
const unmatched = ra.filter((r, i) =>
JSON.stringify(r) !== JSON.stringify(rb[i])
);
expect(unmatched.length).toEqual(0);
});
}
+3 -3
View File
@@ -1,13 +1,13 @@
// Copyright 2017-2021 @polkadot/util authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { randomAsU8a } from '@polkadot/util-crypto';
import { getRandomValues } from '@polkadot/x-randomvalues';
import { performance } from '../../test/performance';
import { arrayRange } from '../array';
import { performance } from '../test/performance';
import { u8aConcat } from '.';
const ptest = arrayRange(10).map(() => randomAsU8a());
const ptest = arrayRange(10).map(() => getRandomValues(new Uint8Array(32)));
describe('u8aConcat', (): void => {
it('concatenates arrays', (): void => {
+1 -1
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2021 @polkadot/util authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { performance } from '../../test/performance';
import { performance } from '../test/performance';
import { u8aEq } from '.';
const ptest = new Uint8Array(32768);
+1 -1
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2021 @polkadot/util authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { performanceCmp } from '../../test/performance';
import { performanceCmp } from '../test/performance';
import { u8aToHex as u8aToHexBuffer } from './toHexBuffer';
import { u8aToHex } from '.';