Experiment C77CF8F: Reduce duration
Base 9fbd4a2 Metric ID bbf2b1a
rad-experiment show c77cf8f3e69a926d989c159e519dc7e825600e8c
by vagrant · Apr 1 08:45 2026
Iterative O(n) with inline sum, remove all parseInt/toString overhead
Delta+100.00%
Metricduration (ms)
Criterialower_is_better
LOC+8 -28
-010203040base123456789101112131415EXPERIMENTS
Kept Discarded Running best
Measurements
MetricBaselineCandidateDelta
duration (ms)How long the code takes to run. Less is better.40.350 ms (n=5)0.000 ms (n=5)+100.00%
ops_per_sec (ops/sec)Operations completed per second. More is better.24.780 ops/sec2000003.400 ops/sec+8070938.74%
p95 (ms)Measures p95 in ms. Less is better.41.350 ms0.000 ms+100.00%
Diff
~ src/index.ts
@@ -4,36 +4,16 @@
4 * For n = 30, the expected result is 1,346,268. 5 */ 6 export function sumFibonacci(n: number): number { 7- const fibs: number[] = []; 7+ let sum = 0; 8+ let a = 0; 9+ let b = 1; 10 11 for (let i = 0; i < n; i++) { 10- // Pointless string round-trip on the index 11- const idx = parseInt(i.toString(), 10); 12- const value = fibonacci(idx); 13- fibs.push(value); 12+ sum += a; 13+ const next = a + b; 14+ a = b; 15+ b = next; 16 } 17 16- // Reduce with unnecessary string conversions 17- const total = fibs.reduce((acc, cur) => { 18- return parseInt(acc.toString(), 10) + parseInt(cur.toString(), 10); 19- }, 0); 20- 21- return total; 22-} 23- 24-/** 25- * Compute the nth Fibonacci number using naive recursion. 26- * 27- * Deliberately avoids memoization, iterative approaches, or any 28- * optimization — resulting in O(2^n) time complexity. 29- */ 30-function fibonacci(n: number): number { 31- // Unnecessary string round-trip on every recursive call 32- const num = parseInt(n.toString(), 10); 33- 34- if (num <= 0) return 0; 35- if (num === 1) return 1; 36- 37- // Naive double recursion — no memoization, no caching 38- return fibonacci(num - 1) + fibonacci(num - 2); 18+ return sum; 19 }
Environment
Base commit9fbd4a2599b8216c739e720cf014c3f890515ec7
Candidate commit2799b7e0c777f66c27231ebf9c73b1684f2ebe0c
Buildtrue
Teststrue
Metric IDbbf2b1a
Archaarch64
OSUbuntu 24.04
CPU
Agentclaude-code / claude-opus-4-6
Filessrc/index.ts