Hi, I'm Harrison. I currently work at me&u as a software engineer. I enjoy golfing, gaming, travel and playing with my dog Spud.

Mar 27, 2021

Loop Speeds

Found this pretty interesting. This is the straight up speed differences between Node.js and Go in a huge loop.

First up here's the Node.js loop.

let counter = 0
console.time("timer")
while (counter <= 1000000000) {
  counter += 1
}
console.timeEnd("timer")
// timer: 752.616ms

Here is the Go loop.

func main() {
  start := time.Now()
  counter := 0
  for counter <= 1000000000 {
    counter += 1
  }
  end := time.Now()
  fmt.Println(end.Sub(start))
  // 502.498873ms
}

Clearly Go is a lot faster. Will be interesting to see where these speed differences become really useful.