diff --git a/README.md b/README.md index f1f3158..c3e09d1 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ The rules: ## Examples +- BigInt vs. number (addition) - Math.hypot or Math.sqrt? - Do local function declarations affect performance? - Do closures affect performance (vs. free functions)? @@ -35,3 +36,29 @@ The rules: - Arguments passing: spread vs. call() vs. apply() - JSON.parse() vs. eval() - ..Add your own? Pull Requests are welcome! + +## Extended Configuration + +In case you test functions operate on differently typed inputs, you might need to provide distinct initial values and provide customized comparison function, otherwise it won't pass the soundness check. Here is an example: + +```js +benchmark('bigint vs number (addition)', { + initialValues() { + const seed = 1000000 + (Math.random() * 1000) | 0 + return { + bigint: BigInt(seed), + number: seed, + } + }, + equal(a, b) { + return BigInt(a) === BigInt(b) + } +}, { + bigint(prev) { + return prev + 1n + }, + number(prev) { + return prev + 1 + } +}) +```