Created
January 17, 2018 13:33
-
-
Save vatson/cd5a9c7b8c98094e68200b69f436e869 to your computer and use it in GitHub Desktop.
Check the speed the rounding inside loop and in loop's condition
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Benchmark = require('benchmark') | |
const suite = new Benchmark.Suite() | |
suite | |
.add('With rounding inside loop', () => { | |
let i = 0 | |
let step = 0.5 | |
while(i < 1000) { | |
i += Math.round(step) | |
} | |
}) | |
.add('With rounding in condition', () => { | |
let i = 0 | |
let step = 0.5 | |
while(Math.round(i) < 1000) { | |
i += step | |
} | |
}) | |
.on('cycle', event => console.log(String(event.target)) ) | |
.on('complete', function() { | |
console.log('Fastest is ' + this.filter('fastest').map('name')) | |
}) | |
.run({ 'async': true }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Results: