diff --git a/api/id/id.go b/api/id/id.go index 071844f4c..e112480a0 100644 --- a/api/id/id.go +++ b/api/id/id.go @@ -47,7 +47,7 @@ func SetMachineIdHost(addr net.IP, port uint16) { func New() Id { var id Id t := time.Now() - // TODO optimize out division by constant (check assembly for compiler optimization) + // NOTE compiler optimizes out division by constant for us ms := uint64(t.Unix())*1000 + uint64(t.Nanosecond()/int(time.Millisecond)) count := atomic.AddUint64(&counter, 1) diff --git a/api/id/id_test.go b/api/id/id_test.go new file mode 100644 index 000000000..a21f21cec --- /dev/null +++ b/api/id/id_test.go @@ -0,0 +1,30 @@ +package id + +import ( + "testing" +) + +func BenchmarkGen(b *testing.B) { + for i := 0; i < b.N; i++ { + id := New() + _ = id + } +} + +func BenchmarkMarshalText(b *testing.B) { + id := New() + for i := 0; i < b.N; i++ { + byts, _ := id.MarshalText() + _ = byts + } +} + +func BenchmarkUnmarshalText(b *testing.B) { + id := New() + byts, _ := id.MarshalText() + for i := 0; i < b.N; i++ { + var id Id + id.UnmarshalText(byts) + _ = id + } +}