Performance test for isCodec vs instanceof (#1543)
This commit is contained in:
@@ -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)
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user