Created
August 2, 2016 19:06
-
-
Save pierrebeaucamp/d01b71e28bc6cdf53ff8404a98869260 to your computer and use it in GitHub Desktop.
Celebrating premature optimization
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
package main | |
import ( | |
"fmt" | |
"time" | |
) | |
func main() { | |
var intTrash int | |
var byteTrash byte | |
now := time.Now() | |
for i := 0; i < 100000000; i++ { | |
var num int | |
for num = 0; num < 8; num++ { | |
intTrash = num | |
} | |
} | |
elapsed1 := time.Since(now) | |
now = time.Now() | |
for i := 0; i < 100000000; i++ { | |
var num byte | |
for num = 0; num < 8; num++ { | |
byteTrash = num | |
} | |
} | |
elapsed2 := time.Since(now) | |
fmt.Println("Integers:", elapsed1) | |
fmt.Println("Bytes:", elapsed2) | |
fmt.Println(intTrash, byteTrash) | |
} |
Author
pierrebeaucamp
commented
Aug 2, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment