fastuuid

package module
v0.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 28, 2023 License: MIT Imports: 2 Imported by: 0

README

PkgGoDev Go Report Card codecov

Fast uuid library, now implemented only UUIDv4 (crypto-random) generators. It generate UUID to string about 50-100ns with one allocation and good paralellism by cpu.

Command for install:

go get github.com/rekby/fastuuid

Example:

package main

import "github.com/rekby/fastuuid"

func main(){
	fmt.Println(fastuuid.MustUUIDv4String())
}

For run benchmarks:

git clone https://github.com/rekby/fastuuid.git
cd fastuuid/benchmarks
go test -test.bench=. -v

Result for macbook pro M1:

goos: darwin
goarch: arm64
pkg: github.com/rekby/fastuuid/benchmarks
BenchmarkRekbyUUID/one-thread                                        13688407               85.92 ns/op            48 B/op          1 allocs/op
BenchmarkRekbyUUID/multi-thread                                      25657815               51.81 ns/op            47 B/op          0 allocs/op
BenchmarkGoogleUUID4/one-thread                                       2256043               530.5 ns/op            64 B/op          2 allocs/op
BenchmarkGoogleUUID4/multi-thread                                     1897683               634.9 ns/op            63 B/op          1 allocs/op
BenchmarkSatoriUUID4/one-thread                                       2277092               531.1 ns/op            64 B/op          2 allocs/op
BenchmarkSatoriUUID4/multi-thread                                     1950952               624.3 ns/op            62 B/op          1 allocs/op
BenchmarkGofrs/one-thread                                             2265781               530.3 ns/op            64 B/op          2 allocs/op
BenchmarkGofrs/multi-thread                                           1912966               635.9 ns/op            63 B/op          1 allocs/op
BenchmarkRogpeppeUnsecuredBecauseItCounter/one-thread                28806307               40.35 ns/op            48 B/op          1 allocs/op
BenchmarkRogpeppeUnsecuredBecauseItCounter/multi-thread               7198768               168.0 ns/op            47 B/op          0 allocs/op
BenchmarkJakehl/one-thread                                            1956322               611.8 ns/op           144 B/op          5 allocs/op
BenchmarkJakehl/multi-thread                                          1963675               643.4 ns/op           142 B/op          4 allocs/op
BenchmarkRwxrob/one-thread                                            1620858               740.5 ns/op           184 B/op          7 allocs/op
BenchmarkRwxrob/multi-thread                                          1870315               644.6 ns/op           182 B/op          6 allocs/op

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func MustUUIDv4

func MustUUIDv4() [16]byte

MustUUIDv4 generate uuid without allocations It will panic if it can't read random data.

It is safe calling this function from concurrent goroutines.

Example
package main

import (
	"fmt"
	"github.com/rekby/fastuuid"
)

func main() {
	var uuid [16]byte = fastuuid.MustUUIDv4()
	fmt.Println(uuid)
}
Output:

func MustUUIDv4String

func MustUUIDv4String() string

MustUUIDv4String generate uuid random string with only one allocation It will panic if it can't read random data.

It is safe calling this function from concurrent goroutines.

Example
package main

import (
	"fmt"
	"github.com/rekby/fastuuid"
)

func main() {
	fmt.Println(fastuuid.MustUUIDv4String())
}
Output:

func MustUUIDv4StringBytes

func MustUUIDv4StringBytes(dst []byte)

MustUUIDv4StringBytes generate uuid and render it as string to dst buffer without allocations It will panic if it can't read random data.

It is safe calling this function from concurrent goroutines.

Example
package main

import (
	"fmt"
	"github.com/rekby/fastuuid"
)

func main() {
	buf := make([]byte, 36)
	fastuuid.MustUUIDv4StringBytes(buf)
	fmt.Println(string(buf))
}
Output:

func UUIDv4

func UUIDv4() (binaryUUID [16]byte, err error)

UUIDv4 generate uuid as byte array without allocations in heap

It is safe calling this function from concurrent goroutines.

func UUIDv4String

func UUIDv4String() (string, error)

UUIDv4String generate uuid random string with only one allocation

It is safe calling this function from concurrent goroutines.

func UUIDv4StringBytes

func UUIDv4StringBytes(buf []byte) error

UUIDv4StringBytes generate uuid and render it as string to dst buffer without allocations

It is safe calling this function from concurrent goroutines.

Types

This section is empty.

Directories

Path Synopsis
ibufio
Package bufio implements buffered I/O. It wraps an io.Reader or io.Writer object, creating another object (Reader or Writer) that also implements the interface but provides buffering and some help for textual I/O.
Package bufio implements buffered I/O. It wraps an io.Reader or io.Writer object, creating another object (Reader or Writer) that also implements the interface but provides buffering and some help for textual I/O.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL