1
0
mirror of synced 2025-12-14 09:08:09 +08:00
Files
SnowFlake-IdGenerator/Go/source/test/main.go
2021-03-30 01:29:03 +08:00

44 lines
821 B
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package main
import (
"C"
"fmt"
"time"
"yitidgen/contract"
"yitidgen/gen"
)
//export NextId
func NextId() uint64{
return gen.GetIns().NextId()
}
func main() {
// 方法一直接采用默认方法生成一个Id
var yid = gen.YitIdHelper{}
fmt.Println(yid.NextId())
// 方法二:自定义参数
var options = contract.NewIdGeneratorOptions(1)
//options.WorkerIdBitLength = 6
//options.SeqBitLength = 6
//options.TopOverCostCount = 2000
//options.BaseTime = time.Date(2020, 2, 20, 2, 20, 2, 20, time.UTC).UnixNano() / 1e6
yid.SetIdGenerator(options)
var times = 50000
for {
var begin = time.Now().UnixNano() / 1e6
for i := 0; i < times; i++ {
yid.NextId()
}
var end = time.Now().UnixNano() / 1e6
fmt.Println(end - begin)
time.Sleep(time.Duration(1000) * time.Millisecond)
}
}