HTML Preparation code:
x
 
1
2
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js'></script>
Script Preparation code:
 
var routes = [];
var numRoutes = 10000;
var lines = 500;
for(var i = 1; i <= numRoutes; i++){
  var numLines = Math.round(Math.random() * lines);
  var lineIds = [];
  for(var j = 0; j <= numLines; j++) {
     lineIds.push(Math.round(Math.random() * lines))
  }
  routes.push({route_id: i, ids: lineIds}); 
}
Tests:
  • Stock

     
    var lines = {};
    routes.forEach(function(d) {
       d.ids.forEach(function(e) {
          lines[e] = (lines[e] || 0) + 1;
       });
    });
    console.log(lines)
  • Alternative

     
    var lines = {};
    for(var i = 1; i <= lines; i++) {
      lines[i] = 0;
    }
    routes.forEach(function(d) {
       d.ids.forEach(function(e) {
          lines[e] = lines[e] + 1;
       });
    });
    console.log(lines)
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    Stock
    Alternative

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 5 years ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36
Chrome 78 on Windows
View result in a separate tab
Test name Executions per second
Stock 16.2 Ops/sec
Alternative 14.5 Ops/sec