Hello Gophers
So it is late in the night here, and I was experimenting with the updated cross compilation functions of Go 1.5 (1.5beta2).
I wrote a triviel program, that calculates all the primes within a range that is defined with a flag parameter.
The source is as following.
package main
import (
"flag"
"fmt"
"time"
)
func isPrime(number int) bool {
if number%2 == 0 {
return number == 2
}
for i := 3; (i * i) <= number; i += 2 {
if number%i == 0 {
return false
}
}
return number != 1
}
func main() {
iteration := flag.Int("m", 0, "loop length")
flag.Parse()
start := time.Now()
for i := 0; i < *iteration; i++ {
isPrime(i)
}
end := time.Since(start)
fmt.Println(end.String())
}
I compiled this in two different versions, one for 32 bit (386) and one for 64 bit (amd64).
Then I ran them to see the performance difference, and I was quite surprised.
C:\Users\Daniel\Desktop>prime_32.exe -m=50000000
34.560019s
C:\Users\Daniel\Desktop>prime_64.exe -m=50000000
1m28.9043318s
Am I missing something (it is kind of late here) or is it normal for 32 bit applications to perform better?
I ran this test on both Windows and Linux, and the difference is the same.