scan-max-index

JavaScript performance comparison

Revision 3 of this test case created by oyiptong

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  function shuffleArray(array) {
      for (var i = array.length - 1; i > 0; i--) {
          var j = Math.floor(Math.random() * (i + 1));
          var temp = array[i];
          array[i] = array[j];
          array[j] = temp;
      }
      return array;
  }
  
  var logData = [[-12.617553539580937,-14.928610815079924,-12.506913661436922,-13.433592934475158,-12.116579099359647,-10.701965116327958,-15.766616660455895,-12.478891632399085,-11.727956329776081,-16.635020553344702,-10.914994079754067,-11.761027910930565,-13.64971154871403,-13.07419260138368,-13.20659593330652,-12.002553784749063,-11.859576005883913,-16.67978302727259,-12.031088702307422,-14.68731682644387,-12.571484505377985,-10.54439208048684,-11.520681731380172,-11.596594789124456,-13.558834750991938,-13.633167781186472,-12.57998593484558,-12.413351544687893,-19.479220311614625,-13.176473984993205,-12.576219040798701,-12.444165622157088,-11.628363115355693,-12.467968645787959,-11.514336745217918,-13.812116829439795,-13.688970613103631,-13.456249370938615,-13.728712667018964,-16.899769037708484,-12.76929222326407,-9.887407093042587,-15.565342345160195,-15.197248363467182,-13.22866012214044,-13.970834220038485,-15.053336763962035,-14.522172321392075,-14.152432184695947,-11.3581668889794,-10.992070652774519,-13.752100167608873,-12.297586457592583,-12.467710073024186,-12.348078662992439,-13.112589023228477,-11.62417106349016,-14.088250720407071],
  [-3.720695898850107,-4.863433499762286,-3.9898818471025796,-7.150276245999542,-2.629828227634927,-2.792897734182504,-5.4715072635628355,-4.942255681304882,-4.166763346665372,-6.600171657784163,-3.2847591923683646,-3.8822749423850227,-4.785664302974838,-4.921516638047635,-4.562492282314993,-4.129897537074119,-4.293836505888779,-7.91523304873064,-4.021214938423646,-6.179890393126733,-2.9865417351766,-2.9557682923640156,-4.4218741627924985,-3.8034125746165683,-5.152559059930429,-4.175154385208301,-3.5145651366908646,-4.747779000658783,-7.35782823510603,-4.317029492696757,-3.977989677006093,-2.975047574436387,-4.156382086338673,-5.259232998385069,-4.575443752750841,-5.458834424449711,-5.320045137781826,-4.296855071802213,-5.808601469868942,-5.658048833416784,-4.565900120782173,-2.105013339669581,-8.448550021011725,-6.134587456554798,-4.348167321940436,-5.554716854328971,-5.897621467485887,-6.188826101499103,-4.082461092627423,-3.6979954241019715,-3.522261645130082,-4.979806336832283,-4.969146675603625,-3.8074652853609368,-3.790812387388264,-4.588389856758729,-4.363098327686061,-5.6453998080301355],
  [-12.44142970490776,-14.898474636148723,-12.168029441190008,-12.990084207125454,-11.780650443625118,-10.700395183566053,-15.897175065625763,-12.525868165646623,-11.840413521959773,-15.978507805699941,-11.077272967181933,-11.53127872096692,-13.96401640853512,-13.150394015207235,-13.292616003744389,-12.055790876156008,-12.121508796355727,-16.332324846685633,-11.729199999849344,-14.478784467197203,-12.204874767250818,-10.549400275429178,-11.573363446313387,-11.64865407827141,-13.863726085807368,-13.23733527660491,-11.686517513886715,-12.300813736536673,-17.41581999518148,-12.590169291511344,-12.432433355279487,-11.784144901460872,-11.274918622701524,-12.65355887596218,-11.558593355590418,-13.929232054419675,-13.832753266866888,-13.76092618132777,-14.529907278995424,-16.501049143921065,-12.691633234053425,-9.592142957630049,-15.149766147131412,-15.092113168053348,-12.618649663922291,-14.205841331887365,-15.078496491468465,-15.04114051303068,-13.692134433252697,-11.147472412270405,-10.994998647381415,-12.096119463120761,-12.254856007155297,-11.99307202751826,-12.091902863357248,-12.847186136520543,-11.7857940181718,-13.781041763206598],
  [-38.13430761336493,-46.11750137833391,-38.1115194926607,-44.68918693721092,-45.874809261100836,-33.98165238846345,-52.23702586575119,-40.22420769485223,-36.644256446854385,-45.572542512202254,-38.55623484963844,-35.07894634157581,-44.535944734025634,-38.567263129253185,-39.57998221477756,-37.07673360353932,-35.49060002831024,-43.65543826745621,-40.63158164024164,-43.12878297632484,-39.19098686884376,-35.472484782529854,-39.91496625992605,-40.79194992593026,-44.00720647997484,-37.08667792535617,-39.74021704128856,-42.42610194264378,-49.01273365566258,-37.93346128613188,-33.96730351992423,-35.9767216010049,-35.71748804326447,-37.80342792555236,-41.0068840491121,-41.98818969027416,-32.6158533698607,-37.14201887131923,-41.50168102288722,-46.662048213697304,-37.7630773025137,-33.24495266337729,-41.79370378348886,-35.17103275646468,-39.258083471597956,-36.67717799897091,-37.14580440838293,-41.468873989599246,-37.67221782114079,-36.75911220226706,-37.21458653450724,-45.85172974023569,-39.05610838772549,-41.68135586353114,-34.304535835403485,-38.71618253297674,-40.16086030678996,-43.33674099425754],
  [-66.37638875490676,-62.89362395749315,-61.66835985409461,-71.33295463486378,-80.34368978376293,-62.57751686852757,-69.63522728662008,-67.4731378569084,-67.0546196026425,-74.28317484579692,-63.50252994690749,-63.560823738629864,-54.46241049692679,-64.31365396793333,-72.99358500398692,-64.12725338295228,-60.983982033561055,-83.3923580093092,-71.83663400311345,-69.12497384397639,-58.816573292983676,-64.12174947019032,-67.16875566221839,-64.98075733575348,-73.09104242102431,-71.55593358263562,-63.56235670902039,-68.53380524566005,-85.39037934877176,-64.31642665343779,-70.10624857016217,-66.04166659301413,-65.40026370819176,-64.1183414017058,-59.86334852007501,-66.26700209374964,-60.73660795468512,-71.32399484541637,-57.05140258627249,-84.10304378330142,-74.53281621745086,-64.64732732792832,-59.993472605456624,-66.00223276967995,-73.42428354532095,-73.84904897376396,-73.99773611499417,-68.34834834085615,-71.37385720256049,-60.52013116105569,-63.0014565159143,-83.44982147234653,-69.8554508674234,-62.38500447170954,-69.9146485194201,-59.32673298285631,-64.73062580265746,-68.74654801650411],
  [-51.8916129300421,-57.82908965757603,-50.580981981505914,-53.34766158235559,-61.96792356479435,-48.57346568125392,-78.07407741397344,-58.03268814461844,-48.39277079707637,-52.63996908084372,-45.877416927113494,-50.07016281977558,-54.43696596858618,-54.869330697460846,-55.407025891960714,-54.34505319069594,-31.354524812301698,-74.25579569281251,-56.60367085164965,-58.25228607399305,-48.111273127266216,-43.19124951839224,-49.19133779351622,-41.56466782930908,-57.35472470132194,-56.97546701297963,-47.487652692387464,-49.65895293032399,-58.46253317087624,-53.74051793606205,-55.552031608422716,-53.40160588336183,-42.45001954561057,-44.59475877497607,-47.06065448151936,-47.40108552531866,-48.24839302335113,-64.23278106753914,-49.35484540783257,-74.77326840126048,-53.77044116219125,-35.38225600091137,-40.010919519082464,-43.10416587361222,-50.89129448306091,-58.23116297654224,-61.84970140617291,-48.357160793763015,-60.678212285606584,-39.672373919575904,-47.13623372701591,-55.38680814375077,-58.73182750687537,-44.91983878264224,-42.88920832670898,-46.87866397662745,-57.33284136394076,-67.81102221435319],
  [-12.666737981969776,-14.072660562369396,-12.479882081134306,-13.539206286722434,-12.1628179210492,-10.736252336675722,-16.7210850080502,-12.843659835923566,-11.762311790279536,-15.573414940895729,-11.437936837286264,-11.666384756821417,-14.34057960268684,-13.108526780297149,-13.18788451910925,-12.061457304616027,-12.282185696983888,-15.820281495458968,-11.956829191178397,-15.341435508063867,-12.51006941448742,-10.47012182306463,-11.665370121108506,-11.686215778744163,-13.625243180494953,-13.38985293563525,-11.901105002729906,-12.49946197593956,-17.778989680483257,-13.017980537775284,-12.559844404787285,-12.175557596739864,-11.91819367592575,-12.695681107288006,-11.83908331255396,-13.481641036331318,-14.331755162699253,-13.711983704303229,-13.6541138436001,-19.19197949984685,-12.83392774061737,-9.97326969069038,-15.429861782786674,-16.183735928974,-13.017868918730475,-13.959024017859234,-15.677291549864233,-15.010220742318,-13.509970671092766,-11.325057637188003,-10.90860732756866,-12.18687947189945,-12.143986147389052,-12.0692857386047,-12.280260245584886,-12.623683752996412,-11.732377415249417,-14.273109062069402],
  [-46.63931541236404,-55.178282747230114,-39.38956044401385,-51.67970639621832,-44.579296992866155,-32.022738954168105,-52.08177965754357,-42.67912934456746,-41.90220617130904,-39.05822337594641,-34.0700579727978,-39.46985132812483,-43.529960446998274,-44.895096514202834,-50.021313521373315,-42.87681068981651,-34.96294251342488,-47.369513434994,-40.82770728642326,-45.26034179593231,-44.58997144986569,-43.33977910721143,-40.13198848959598,-40.99778177289454,-50.41288519226619,-48.83061388473939,-40.47935073748026,-38.71469835380537,-46.00587851250939,-43.402195819156695,-43.69497823844221,-42.6552606442081,-42.3681665167579,-42.0603874205484,-38.66331552179187,-47.680550754689065,-42.70775868900853,-43.19752372508773,-45.0058965505204,-51.19990388513691,-53.32453422041934,-33.55406855772923,-40.573563921694344,-40.43173073295148,-45.70038544886626,-50.12471454827279,-47.08901395363529,-43.516689550968806,-46.38333506661628,-39.38875403932311,-40.25128521609403,-51.145144566833224,-43.821869168756635,-40.623324807445115,-43.53620606378688,-45.17437549526734,-39.616013061282445,-49.94015090074187],
  [-12.61654099672749,-14.850709014366576,-12.628567696841042,-12.9568397415301,-12.406470223616788,-10.80359734170477,-15.200923709195543,-12.759013127622904,-12.036450877679648,-15.95387851120473,-11.035684036984017,-11.667203429928875,-14.131766293547138,-13.08702998788244,-13.474459826260537,-12.036542383920402,-12.096015828738217,-17.27632467114228,-11.902844469951962,-14.833306469409662,-12.567903459710434,-10.469547179514972,-11.42465250887998,-11.657157869086904,-13.731066098133171,-13.424368029741537,-12.084882910601916,-12.278914578756579,-19.479220311614625,-12.750094405581635,-12.721918733052819,-12.16549250508719,-11.598304099769067,-12.360284266679244,-11.592109889622158,-14.164833254615353,-13.781657155028736,-13.978184091965206,-13.82328397820297,-19.19197949984685,-13.049778864247608,-9.940436862056739,-16.101486709033377,-14.951382217346548,-13.24064631115889,-14.017432443368538,-15.36356773289742,-15.25796073993391,-13.976835314060331,-11.293250992782875,-10.919618529583992,-12.380879554888491,-12.134682105761456,-12.330755763765406,-12.402271079384533,-13.159021163793467,-11.825420731213168,-14.42661807344269],
  [-3.720695898850107,-4.863433499762286,-3.9898818471025796,-7.150276245999542,-2.629828227634927,-2.792897734182504,-5.4715072635628355,-4.942255681304882,-4.166763346665372,-6.600171657784163,-3.2847591923683646,-3.8822749423850227,-4.785664302974838,-4.921516638047635,-4.562492282314993,-4.129897537074119,-4.293836505888779,-7.91523304873064,-4.021214938423646,-6.179890393126733,-2.9865417351766,-2.9557682923640156,-4.4218741627924985,-3.8034125746165683,-5.152559059930429,-4.175154385208301,-3.5145651366908646,-4.747779000658783,-7.35782823510603,-4.317029492696757,-3.977989677006093,-2.975047574436387,-4.156382086338673,-5.259232998385069,-4.575443752750841,-5.458834424449711,-5.320045137781826,-4.296855071802213,-5.808601469868942,-5.658048833416784,-4.565900120782173,-2.105013339669581,-8.448550021011725,-6.134587456554798,-4.348167321940436,-5.554716854328971,-5.897621467485887,-6.188826101499103,-4.082461092627423,-3.6979954241019715,-3.522261645130082,-4.979806336832283,-4.969146675603625,-3.8074652853609368,-3.790812387388264,-4.588389856758729,-4.363098327686061,-5.6453998080301355]];
  logData.forEach(function(value, index){
    logData[index] = shuffleArray(logData[index]);
  });

};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
forEach
var indexes = [];
logData.forEach(function(dataArray){
  var max_value = -Infinity;
  var max_index = -1;
  dataArray.forEach(function(value, index){
    if(value > max_value) {
      max_value = value;
      max_index = index;
    }
  });
  indexes.push(max_index);
});
pending…
Math.max.apply
var indexes = [];
logData.forEach(function(dataArray){
 indexes.push(dataArray.indexOf(Math.max.apply(Math, dataArray)));
});
pending…
for..in
var indexes = [];
for (var dataIndex in logData) {
  var dataArray = logData[dataIndex];
  var max_value = -Infinity;
  var max_index = -1;
  for (var valueIndex in dataArray) {
    var value = dataArray[valueIndex];
    if(value > max_value) {
      max_value = value;
      max_index = valueIndex;
    }
  }
  indexes.push(max_index);
}
pending…
for..of
var indexes = [];
for (var dataArray of logData) {
  var max_value = -Infinity;
  var max_index = -1;
  var index = 0;
  for (var value of dataArray) {
    index += 1;
    if(value > max_value) {
      max_value = value;
      max_index = index;
    }
  }
  indexes.push(max_index);
}
pending…
for loop
var indexes = [];
for (var dataIndex = 0; dataIndex < logData.length; dataIndex++) {
  var dataArray = logData[dataIndex];
  var max_value = -Infinity;
  var max_index = -1;
  for (var valueIndex = 0; valueIndex < dataArray.length; valueIndex++) {
    var value = dataArray[valueIndex];
    if(value > max_value) {
      max_value = value;
      max_index = valueIndex;
    }
  }
  indexes.push(max_index);
}
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL.

0 Comments