镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Commit 58b1bc6

Browse files
committed
bench: preserve recursive call observability (#58)
1 parent 30d5867 commit 58b1bc6

3 files changed

Lines changed: 13 additions & 7 deletions

File tree

‎bench/comparison.js‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,21 @@ function benchmarkArrays(jobs, lane) {
4343
return total;
4444
}
4545

46-
function benchmarkFibValue(n) {
47-
return n < 2 ? n : benchmarkFibValue(n - 1) + benchmarkFibValue(n - 2);
46+
function benchmarkFibValue(n, state) {
47+
// Keep each call observable so this row continues measuring recursive call
48+
// throughput even when an engine can recognize and memoize the pure
49+
// recurrence. The state is invocation-local, so shared-realm lanes never
50+
// race one counter or produce schedule-dependent checksums.
51+
state.calls = state.calls + 1;
52+
return n < 2 ? n : benchmarkFibValue(n - 1, state) + benchmarkFibValue(n - 2, state);
4853
}
4954

5055
function benchmarkFibonacci(jobs, lane) {
5156
var total = lane;
57+
var state = { calls: 0 };
5258
for (var job = 0; job < jobs; job = job + 1)
53-
total = total + benchmarkFibValue(24);
54-
return total;
59+
total = total + benchmarkFibValue(24, state);
60+
return total + state.calls;
5561
}
5662

5763
function benchmarkFunction(name) {

‎docs/benchmarks.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Both runners evaluate the exact source in [`bench/comparison.js`](../bench/compa
4545
| `arithmetic` | 100,000 integer additions and modulo operations |
4646
| `properties` | 25,000 rounds mutating four properties on one object |
4747
| `arrays` | push 10,000 integers, then read and sum the array |
48-
| `fibonacci` | recursively evaluate `fib(24)` |
48+
| `fibonacci` | recursively evaluate `fib(24)` while incrementing an invocation-local observable call counter |
4949

5050
The compared modes are intentionally explicit:
5151

‎tools/benchmark-comparison.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
# Equal work is used for both engines. These counts keep the fastest row
2121
# above the full-run 50 ms timing floor on the reference M3 Pro while
2222
# keeping the shared-realm stress matrix practical.
23-
"arithmetic": 80,
23+
"arithmetic": 160,
2424
"properties": 80,
25-
"arrays": 180,
25+
"arrays": 450,
2626
"fibonacci": 24,
2727
}
2828

0 commit comments

Comments
 (0)