UNPKG

confusablematcher-js-interop

Version:

TypeScript NAPI Interop for ConfusableMatcher.

25 lines (21 loc) 874 B
import type Benchmark from 'benchmark'; import type { StrPosPointer } from '../../binding'; // import { assert } from 'console'; import type { ConfusableMatcher } from '../../wrapper'; import type { ConfigureFn } from '../bench'; let ptr: StrPosPointer; export const configure: ConfigureFn = (suite: Benchmark.Suite, cm: ConfusableMatcher) => { suite.add('ConfusableMatcher#indexOf (StrPosPointers)', { defer: true, fn: (defer: Benchmark.Deferred) => { // assert(ptr !== undefined); cm.indexOf('SIMP', 'SIMP', { matchOnWordBoundary: true, matchRepeating: true, needlePosPointers: ptr, }).finally(() => defer.resolve()); }, onComplete: () => cm.freeStringPosPointers(ptr), onStart: () => (ptr = cm.computeStringPosPointers('SIMP')), }); };