Skip to content
TheChatArchiveThe Chat Archive
o4-mini-2025-04-16· OpenAIHugging Face LMArena Human Preference 140K

write the fastest implementation of fibonachi sequence to calculate as much numbers as…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Geminigemini-2.0-flash-001’s answer.
  1. User

    write the fastest implementation of fibonachi sequence to calculate as much numbers as possible for 1 second

    in js

  2. Assistant

    Here’s a self‑contained Node.js (or modern‑browser) example that runs a 1 second loop adding Fibonacci numbers with BigInt, counting how many you can compute in that time. It uses the fastest inner loop possible (no destructuring, no recursion, just simple addition and variable swaps) and high‑resolution timers.

    // If you run under Node.js, uncomment the next line:
    // const { performance } = require('perf_hooks');
    
    function fibBenchmark(durationMs = 1000) {
      // High‑res start time (in milliseconds)
      const t0 = performance.now();
    
      // F(0) = 0n, F(1) = 1n
      let a = 0n,
          b = 1n,
          n = 1;           // we've "computed" F(1) already
    
      // Keep going until we've spent durationMs
      while (performance.now() - t0 < durationMs) {
        // a <- b, b <- a + b
        const c = a + b;
        a = b;
        b = c;
        n++;
      }
    
      // When we exit, `n` is the first index *beyond* the last fully computed
      // so the largest valid index is n-1, whose value is a:
      return { iterations: n - 1, fibValue: a };
    }
    
    // Run a 1 second benchmark
    const result = fibBenchmark(1000);
    console.log(`Computed up to F(${result.iterations}) in 1 second`);
    console.log(`F(${result.iterations}) has ${result.fibValue.toString().length} digits`);
    

    Explanation of the key points:

    • We use BigInt (0n, 1n) so we can grow without overflow.
    • We avoid fat‑pointer arrays or destructuring in the hot loop—just three BigInt operations and two assignments per iteration.
    • We measure time with performance.now() (sub‑millisecond precision). In Node.js you may need to pull it in from perf_hooks.
    • At the end we report the highest Fibonacci index fully computed within the time window, plus how many digits that number has.

    You can tweak durationMs (in milliseconds) to any time budget you like. This approach maximizes the number of Fibonacci additions in your 1 second window.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.