mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
@@ -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)
|
||||
|
||||
|
||||
30
api/id/id_test.go
Normal file
30
api/id/id_test.go
Normal file
@@ -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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user