Hello all
We have an app on linux/amd64 that calls time.Now quite frequently.
We're interested in the UnixNano value, so I did some benchmarks that uses
the vDSO work from a while back:
http://code.google.com/p/go/source/detail?r=56ea40aac72b
I think it might be of interest:
package time_test
import (
"syscall"
"testing"
"time"
)
func now() time.Time {
var tv syscall.Timeval
syscall.Gettimeofday(&tv)
return time.Unix(0, syscall.TimevalToNsec(tv))
}
func BenchmarkTimeNow(b *testing.B) {
for i := 0; i < b.N; i++ {
time.Now()
}
}
func BenchmarkNowGettimeofday(b *testing.B) {
for i := 0; i < b.N; i++ {
now()
}
}
X5675 running 3.3.8-1.fc16.x86_64:
BenchmarkTimeNow 1000000 1030 ns/op
BenchmarkNowGettimeofday 2000000 767 ns/op
E5-2670 running 3.4.7-1.fc16.x86_64:
BenchmarkTimeNow 1000000 1124 ns/op
BenchmarkNowGettimeofday 2000000 759 ns/op
i7-3720QM running 3.6.3-1.fc17.x86_64:
BenchmarkTimeNow 5000000 422 ns/op
BenchmarkNowGettimeofday 20000000 85.7 ns/op
syscall.Time is also a winner if you only need second precision.
Go version here is 96fde1b15506. Not quite ready for 64-bit ints yet.
The E5-2670 numbers seem a bit off. I'll update to 3.6 soon and retest. I'm
guessing it's a kernel thing since I can't imagine the i7 being that much
faster, but maybe it is...
Maybe there's some scope here for tweaking the time.Now implementation on
linux/amd64?
Regards
Albert