Script Preparation code:
x
 
  function searchMostCommonNumber(arr) {
    if (arr === void 0) {
      arr = [];
    }
    var current = 0;
    var max = 0;
    var mostCommonNumber = 0;
    var i;
    for (i = 0; i < arr.length - 1; i++) {
      var current_1 = 1;
      var j = void 0;
      for (j = i + 1; j < arr.length; j++) {
        if (arr[i] === arr[j]) {
          current_1++;
        }
      }
      if (current_1 > max) {
        max = current_1;
        mostCommonNumber = arr[i];
      }
    }
    return mostCommonNumber;
  }
function mostCommonNumber(numbers) {
    let map = new Map()
    for (let num of numbers) {
        map.set(num, (map.get(num) || 0) + 1)
    }
    let mostCommonNumber = NaN
    let maxCount = -1
    for (let [num, count] of map.entries()) {
        if (count > maxCount) {
            maxCount = count
            mostCommonNumber = num
        }
    }
    return mostCommonNumber
}
numbers = Array(1e2).map(n => Math.floor(Math.random() * 1000))
Tests:
  • searchMostCommonNumber

     
    searchMostCommonNumber(numbers)
  • mostCommonNumber

     
    mostCommonNumber(numbers)
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    searchMostCommonNumber
    mostCommonNumber

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 7 years ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36
Chrome 61 on Windows
View result in a separate tab
Test name Executions per second
searchMostCommonNumber 6758.5 Ops/sec
mostCommonNumber 131856.2 Ops/sec