switch contains

JavaScript performance comparison

Test case created by Kenan Yildirim

Preparation code

<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/1.3.1/lodash.min.js"></script>
<script>
Benchmark.prototype.setup = function() {
    var array = [
      'ingame',
      'recent_games',
      'runes',
      'mastery',
      'leagues',
      'ranked_stats',
      'teams'
    ];
    var path = 'http://api.captainteemo.com/player/na/zamphira/mastery';
};
</script>

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
switch
var hasSecondSuccess;
switch (false) {
  case !(_.contains(path, 'ingame')):
    hasSecondSuccess = true;
    break;
  case !(_.contains(path, 'recent_games')):
    hasSecondSuccess = true;
    break;
  case !(_.contains(path, 'runes')):
    hasSecondSuccess = true;
    break;
  case !(_.contains(path, 'mastery')):
    hasSecondSuccess = true;
    break;
  case !(_.contains(path, 'leagues')):
    hasSecondSuccess = true;
    break;
  case !(_.contains(path, 'ranked_stats')):
    hasSecondSuccess = true;
    break;
  case !(_.contains(path, 'teams')):
    hasSecondSuccess = true;
    break;
  default:
    hasSecondSuccess = false;
}
pending…
forEach
var hasSecondSuccess = false;
_(array).forEach(function(value) {
  if (_.contains(path, value)){
    hasSecondSuccess = true;
    return false;
  }
});
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. Here’s a list of current revisions for this page:

0 comments

Add a comment