Snowflake ID generating in Go
APACHE-2.0 License
FastID is a pluggable unique ID generator in Go.
go get github.com/beinan/fastid
Generate an ID
import (
"fmt"
"github.com/beinan/fastid"
)
func ExampleGenInt64ID() {
id := fastid.CommonConfig.GenInt64ID()
fmt.Printf("id generated: %v", id)
}
With this setting, FastID is able to generate 128(2^7) unique IDs per millisecond (1.048576 millisecond, 2^10 nanosecond).
See the examples in GoDoc
go test -bench=.
goos: linux
goarch: amd64
pkg: github.com/beinan/fastid
BenchmarkGenID-4 20000000 79.7 ns/op
BenchmarkGenIDP-4 20000000 141 ns/op
PASS
ok github.com/beinan/fastid 4.779s