niklas-heer / speed-comparison

A repo which compares the speed of different programming languages.
https://niklas-heer.github.io/speed-comparison
MIT License
475 stars 76 forks source link

I suppose JS can run faster in 'strict' mode #119

Open ghost opened 11 months ago

ghost commented 11 months ago

Quick check with just a laptop browser shows 202-205ms instead of ~1300ms

"use strict" // is really more perfomant
console.time("test")
var rounds = 10e7 // var is more natural = faster

var x = 1
var pi = 1

for (var i = 2; i < rounds + 2; i++) {
    x *= -1
    pi += x / (2 * i - 1)
}

pi *= 4
console.timeEnd("test")