Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36
Chrome 130
Windows
Desktop
5 months ago
Test name Executions per second
reverse 30.1 Ops/sec
sort 30.3 Ops/sec
HTML Preparation code:
AخA
 
1
var array = Array.from({ length: 10000 }, () => Math.floor(Math.random() * 10000))
Script Preparation code:
 
var array = Array.from({ length: 10000 }, () => Math.floor(Math.random() * 10000))
Tests:
  • reverse

    x
     
    array.forEach(n => {
      const repeat = Math.sqrt(n);
      const result = [[], []];
      for (let i = 1; i <= repeat; i++) { 
              if(n % i === 0) {
                  result.push(i);
                  if (i !== repeat) result.push(n / i);
              }
      }
      result.sort().reverse()[0];
      }
    )
  • sort

     
    array.forEach(n => {
      const repeat = Math.sqrt(n);
      const result = [[], []];
      for (let i = 1; i <= repeat; i++) { 
              if(n % i === 0) {
                  result.push(i);
                  if (i !== repeat) result.push(n / i);
              }
      }
      result.sort()[result.length-1];
      }
    )