JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
See the developer console for results!
JavaScript
function s() {
return 1;
}
function ordinary_loop() {
var count = 0;
for (var i = 0; i < 10; i++) {
count += s();
}
}
function unrolled_loop() {
var count = 0;
count += s();
count += s();
count += s();
count += s();
count += s();
count += s();
count += s();
count += s();
count += s();
count += s();
}
// Run benchmark:
var suite = new Benchmark.Suite;
suite
.add('ordinary loop', ordinary_loop)
.add('unrolled loop', unrolled_loop)
.on('cycle', function(event) {
console.log(event.target.toString());
})
.on('complete', function() {
console.log('Fastest is ' + this.filter('fastest').pluck('name'));
})
.run({'async': false});