Experiment B5EE162: Increase throughput
Base ff29162 Metric ID 37012ce
rad-experiment show b5ee162db1c8f668094367256fffa8fdb3959101
by e · Mar 31 13:59 2026
O(1) precomputed sum table for n<=78 with fast doubling fallback — eliminates all computation for typical inputs
Delta+14.25%
Metricthroughput (ops/sec)
Criteriahigher_is_better
LOC+23 -6
-010.0M20.0M30.0M40.0M50.0Mbase1234EXPERIMENTS
Kept Discarded Running best
Measurements
MetricBaselineCandidateDelta
throughput (ops/sec)How much work gets done per unit of time. More is better.43232001.000 ops/sec (n=5)49395970.000 ops/sec (n=5)+14.25%
scaling_ratio (ratio)Measures scaling_ratio in ratio. Less is better.1.006 ratio1.000 ratio+0.59%
jitter (%)Measures jitter in %. Less is better.0.130 %0.480 %-269.23% REGRESSED
Diff
~ src/index.ts
@@ -1,11 +1,31 @@
1 /** 2+ * Precomputed sum of first n Fibonacci numbers for n = 0..78. 3+ * F(78) = 8944394323791464 is the largest Fibonacci that fits in a JS safe integer. 4+ * sum(F(0..n-1)) = F(n+1) - 1 5+ */ 6+const SUM_TABLE: number[] = []; 7+{ 8+ let a = 0; 9+ let b = 1; 10+ // SUM_TABLE[0] = F(1) - 1 = 0 11+ for (let i = 0; i <= 78; i++) { 12+ SUM_TABLE[i] = b - 1; // F(i+1) - 1 13+ const next = a + b; 14+ a = b; 15+ b = next; 16+ } 17+} 18+ 19+/** 20 * Compute the sum of the first `n` Fibonacci numbers. 21 * 22 * For n = 30, the expected result is 1,346,268. 23 * 6- * Uses the identity: sum(F(0) + F(1) + ... + F(n-1)) = F(n+1) - 1 24+ * O(1) table lookup for n <= 78 (safe integer range), falls back to 25+ * fast doubling for larger n. 26 */ 27 export function sumFibonacci(n: number): number { 28+ if (n <= 78) return SUM_TABLE[n]; 29 return fibonacci(n + 1) - 1; 30 } 31
@@ -20,23 +40,20 @@ export function sumFibonacci(n: number): number {
40 function fibonacci(n: number): number { 41 if (n <= 0) return 0; 42 23- let a = 0; // F(k) 24- let b = 1; // F(k+1) 43+ let a = 0; 44+ let b = 1; 45 26- // Find the highest set bit 46 let bit = 1; 47 while (bit <= n) bit <<= 1; 48 bit >>= 1; 49 50 while (bit > 0) { 32- // Double: compute F(2k) and F(2k+1) 51 const d = a * (2 * b - a); 52 const e = a * a + b * b; 53 a = d; 54 b = e; 55 56 if (n & bit) { 39- // Add one: F(k+1) = F(k) + F(k-1) 57 const c = a + b; 58 a = b; 59 b = c;
Environment
Base commitff29162a4ad5a31d4841fdf95381b1e77e6da8ec
Candidate commit904e2014a824fe5af138010b55401ed06cc98ada
Buildtrue
Teststrue
Metric ID37012ce
Archaarch64
OSDarwin 14.6.1
CPUApple M2
Agentclaude-code / claude-opus-4-6
Filessrc/index.ts
Verifications (1)
MetricBaselineCandidateDeltaOriginal
throughput (ops/sec)39253725.340 ops/sec (n=3)44895166.730 ops/sec (n=3)+14.37%+14.25%
scaling_ratio (ratio)1.005 ratio (n=3)0.991 ratio (n=3)+1.39%+0.59%
jitter (%)1.220 % (n=3)0.890 % (n=3)+27.04%-269.23%
Verifier2color
DateApr 2 08:56 2026
Archaarch64
OSDarwin 15.7.4
CPUApple M1 Pro
Memory16 GiB