Skip to content

Instantly share code, notes, and snippets.

@sebdeckers
Created May 3, 2017 03:45
Show Gist options
  • Select an option

  • Save sebdeckers/f110f4c5f65fc70da39587cb5d0fba68 to your computer and use it in GitHub Desktop.

Select an option

Save sebdeckers/f110f4c5f65fc70da39587cb5d0fba68 to your computer and use it in GitHub Desktop.

Revisions

  1. sebdeckers created this gist May 3, 2017.
    21 changes: 21 additions & 0 deletions bench-loops.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    var Benchmark = require('benchmark');
    var suite = new Benchmark.Suite;
    var arr = [1,2,3,4,5,6,7,8,9,0]
    suite.add('for', function() {
    for (var i = 0, len = arr.length; i < len; i++) {
    var item = arr[i];
    item + 1;
    }
    })
    .add('for-of', function() {
    for (var item of arr) {
    item + 1;
    }
    })
    .on('cycle', function(event) {
    console.log(String(event.target));
    })
    .on('complete', function() {
    console.log('Fastest is ' + this.filter('fastest').map('name'));
    })
    .run({ 'async': true });