From 27ea13401dfa443243d588c5636c85e1037b986d Mon Sep 17 00:00:00 2001 From: Uri Shaked Date: Sun, 1 Dec 2019 23:18:22 +0200 Subject: feat: improve benchmark code compare 3 alternatives: 1. Current avrInstruction() implementation 2. Map opcodes using a Javascript map 3. Map opcodes using a Uint16Array and big switch statement --- benchmark/permutations.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 benchmark/permutations.ts (limited to 'benchmark/permutations.ts') diff --git a/benchmark/permutations.ts b/benchmark/permutations.ts new file mode 100644 index 0000000..4465557 --- /dev/null +++ b/benchmark/permutations.ts @@ -0,0 +1,23 @@ +export function* permutations(pattern: string) { + let totalPerms = 1; + for (const char of pattern) { + if (char !== '0' && char !== '1') { + totalPerms *= 2; + } + } + + for (let permIndex = 0; permIndex < totalPerms; permIndex++) { + let varIndex = 0; + let value = 0; + for (const char of pattern) { + value *= 2; + if (char === '1') { + value++; + } else if (char !== '0') { + value += permIndex & (1 << varIndex) ? 1 : 0; + varIndex++; + } + } + yield value; + } +} -- cgit v1.2.3