Performance test for isCodec vs instanceof (#1543)

This commit is contained in:
Jaco
2022-06-18 08:58:59 +03:00
committed by GitHub
parent e038c36719
commit d771d4c243
+15
View File
@@ -1,8 +1,17 @@
// Copyright 2017-2022 @polkadot/util authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { performanceCmp } from '../test/performance';
import { isCodec } from '.';
const ptest = {
registry: {
get: () => null
},
toHex: () => '0x',
toU8a: () => new Uint8Array()
};
describe('isCodec', (): void => {
it('is false on no value', (): void => {
expect(isCodec()).toEqual(false);
@@ -37,4 +46,10 @@ describe('isCodec', (): void => {
})
).toEqual(false);
});
performanceCmp('isCodec', ['isCodec', 'instanceof'], 500_000, [[ptest]], (v: unknown, isSecond) =>
isSecond
? !(v instanceof String)
: isCodec(v)
);
});