HTML Preparation code:
AخA
 
1
<!--your preparation HTML code goes here-->
Script Preparation code:
 
/*your preparation JavaScript code goes here
To execute async code during the script preparation, wrap it as function globalMeasureThatScriptPrepareFunction, example:*/
async function globalMeasureThatScriptPrepareFunction() {
    // This function is optional, feel free to remove it.
    // await someThing();
}
Tests:
  • Me

    x
     
    const arr = [8, 9, 3, 9, 6, 5, 1, 7, 3, 9, 4, 1, 7, 2, 8, 3, 2, 1, 4, 7];
    const small5 = [arr[0]];
    const big5 = [arr[0]];
    for (const n of arr.slice(1)) {
      if (n < small5[4] || small5.length < 5) {
        for (let i = 0; i < 5; ++i) {
          if (n < small5[i] || i === small5.length - 1) {
            small5.splice(i, 0, n);
            break;
          }
        }
      }
      if (n > big5[4] || big5.length < 5) {
        for (let i = 0; i < 5; ++i) {
          if (n > big5[i]) {
            big5.splice(i, 0, n);
            break;
          } else if (i === big5.length - 1) {
            big5.push(n);
            break;
          }
        }
      }
    }
    let total = 0;
    for (let i = 0; i < 5; ++i) {
      total += small5[i] + big5[i];
    }
  • Chatgpt

     
    const arr = [8, 9, 3, 9, 6, 5, 1, 7, 3, 9, 4, 1, 7, 2, 8, 3, 2, 1, 4, 7];
    const small5 = [];
    const big5 = [];
    for (const n of arr) {
      // Maintain 5 smallest numbers
      if (small5.length < 5 || n < small5[4]) {
        small5.push(n);
        small5.sort((a, b) => a - b); // Ensure the smallest numbers are sorted
        if (small5.length > 5) small5.pop(); // Keep only the smallest 5
      }
      // Maintain 5 largest numbers
      if (big5.length < 5 || n > big5[4]) {
        big5.push(n);
        big5.sort((a, b) => b - a); // Ensure the largest numbers are sorted
        if (big5.length > 5) big5.pop(); // Keep only the largest 5
      }
    }
    // Calculate the total sum
    const total = small5.reduce((sum, num) => sum + num, 0) +
                  big5.reduce((sum, num) => sum + num, 0);
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    Me
    Chatgpt

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 3 months ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Chrome 131 on Windows
View result in a separate tab
Test name Executions per second
Me 707017.1 Ops/sec
Chatgpt 221905.9 Ops/sec