Experiment 5C9FCBC: Reduce duration
Base cf0ad0f Metric ID bbf2b1a
rad-experiment show 5c9fcbcdbd9557a2f2ef9a9c2c1368452c3b2066
by vagrant · Mar 31 14:38 2026
Fast doubling O(log n) with sum identity F(n+1)-1 — both at timer floor for duration, but ops_per_sec regresses due to recursive call overhead at n=30
Delta-0.00%
Metricduration (ms)
Criterialower_is_better
LOC+14 -13
-010203040base123456789101112131415EXPERIMENTS
Kept Discarded Running best
Measurements
MetricBaselineCandidateDelta
duration (ms)How long the code takes to run. Less is better.0.000 ms (n=5)0.000 ms (n=5)-0.00%
ops_per_sec (ops/sec)Operations completed per second. More is better.1999995.950 ops/sec888888.560 ops/sec-55.55% REGRESSED
p95 (ms)Measures p95 in ms. Less is better.0.000 ms0.000 ms-0.00%
Diff
~ src/index.ts
@@ -3,22 +3,23 @@
3 * 4 * For n = 30, the expected result is 1,346,268. 5 * 6- * Uses iterative approach: O(n) time, O(1) space. 7- * Computes fibonacci values and accumulates sum in a single pass. 6+ * Uses the identity: sum(F(0)..F(n-1)) = F(n+1) - 1 7+ * Combined with fast doubling for O(log n) time. 8 */ 9 export function sumFibonacci(n: number): number { 10 if (n <= 0) return 0; 11+ const [a] = fastDoubling(n + 1); 12+ return a - 1; 13+} 14 12- let sum = 0; 13- let a = 0; 14- let b = 1; 15- 16- for (let i = 0; i < n; i++) { 17- sum += a; 18- const next = a + b; 19- a = b; 20- b = next; 15+// Returns [F(n), F(n+1)] using fast doubling in O(log n) time 16+function fastDoubling(n: number): [number, number] { 17+ if (n === 0) return [0, 1]; 18+ const [a, b] = fastDoubling(n >> 1); 19+ const c = a * (2 * b - a); 20+ const d = a * a + b * b; 21+ if (n & 1) { 22+ return [d, c + d]; 23 } 22- 23- return sum; 24+ return [c, d]; 25 }
Environment
Base commitcf0ad0f9f2ca832f45ee2b30101beb9493ae69ac
Candidate commit00226c9aa6afdbf6b0d9be7c71fa8a7eaa70efec
Buildtrue
Teststrue
Metric IDbbf2b1a
Archaarch64
OSLinux 6.8.0-86-generic
CPU-
Agentclaude-code / claude-opus-4-6
Filessrc/index.ts