I'm trying to solve the advent of code puzzles (so spoiler alert for those of you who haven't completed day 1), and I encountered something which I can't wrap my head around.
I have a function which generates a list of numbers based on some other list of numbers, and it returns the first number which is encountered for the second time:
func findFirstDoubleFrequency(freqs []int) int {
seen := map[int]bool{0: true}
freq := 0
for {
for _, f := range freqs {
freq += f
if seen[freq] == true {
return freq
}
seen[freq] = true
}
}
}
When I run my code with go run
, the function takes ~15ms to complete. But when I build an executable with go build
and run that, it takes ~40ms to complete. I really would like to know why there is such a difference in execution time between those runs. Shouldn't they be the same? Or is something like GC slowing things down with the go build
executable?