Skip to content

Instantly share code, notes, and snippets.

@hnakamur
Created July 21, 2017 11:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hnakamur/8a084c753102e8954182379a2ab3bd8d to your computer and use it in GitHub Desktop.
Save hnakamur/8a084c753102e8954182379a2ab3bd8d to your computer and use it in GitHub Desktop.
benchmark of github.com/ybubnov/go-uuid and github.com/google/uuid
package main
import (
"testing"
"github.com/google/uuid"
linuxuuid "github.com/ybubnov/go-uuid"
)
func BenchmarkLinuxKernelUUIDv4(b *testing.B) {
src := linuxuuid.Kernel{MaxIdle: 128, MaxProcs: 16}
defer src.Stop()
for i := 0; i < b.N; i++ {
_, err := src.Next()
if err != nil {
b.Error(err)
}
}
}
func BenchmarkGoogleUUIDv4(b *testing.B) {
for i := 0; i < b.N; i++ {
_, err := uuid.NewRandom()
if err != nil {
b.Error(err)
}
}
}
@hnakamur
Copy link
Author

$ go test -count=10 -run=NONE -bench=. -benchmem
goos: linux
goarch: amd64
pkg: bitbucket.org/hnakamur/uuidv4-benchmark
BenchmarkLinuxKernelUUIDv4-2      300000              5613 ns/op             168 B/op          4 allocs/op
BenchmarkLinuxKernelUUIDv4-2      300000              5655 ns/op             168 B/op          4 allocs/op
BenchmarkLinuxKernelUUIDv4-2      300000              5651 ns/op             168 B/op          4 allocs/op
BenchmarkLinuxKernelUUIDv4-2      300000              5665 ns/op             168 B/op          4 allocs/op
BenchmarkLinuxKernelUUIDv4-2      300000              5678 ns/op             168 B/op          4 allocs/op
BenchmarkLinuxKernelUUIDv4-2      300000              5683 ns/op             168 B/op          4 allocs/op
BenchmarkLinuxKernelUUIDv4-2      300000              5711 ns/op             168 B/op          4 allocs/op
BenchmarkLinuxKernelUUIDv4-2      300000              5675 ns/op             168 B/op          4 allocs/op
BenchmarkLinuxKernelUUIDv4-2      300000              5682 ns/op             168 B/op          4 allocs/op
BenchmarkLinuxKernelUUIDv4-2      300000              5726 ns/op             168 B/op          4 allocs/op
BenchmarkGoogleUUIDv4-2          1000000              1824 ns/op              16 B/op          1 allocs/op
BenchmarkGoogleUUIDv4-2          1000000              1871 ns/op              16 B/op          1 allocs/op
BenchmarkGoogleUUIDv4-2          1000000              1871 ns/op              16 B/op          1 allocs/op
BenchmarkGoogleUUIDv4-2          1000000              1875 ns/op              16 B/op          1 allocs/op
BenchmarkGoogleUUIDv4-2          1000000              1866 ns/op              16 B/op          1 allocs/op
BenchmarkGoogleUUIDv4-2          1000000              1887 ns/op              16 B/op          1 allocs/op
BenchmarkGoogleUUIDv4-2          1000000              1912 ns/op              16 B/op          1 allocs/op
BenchmarkGoogleUUIDv4-2          1000000              1886 ns/op              16 B/op          1 allocs/op
BenchmarkGoogleUUIDv4-2          1000000              1868 ns/op              16 B/op          1 allocs/op
BenchmarkGoogleUUIDv4-2          1000000              1832 ns/op              16 B/op          1 allocs/op
PASS
ok      bitbucket.org/hnakamur/uuidv4-benchmark 36.546s
$ go version
go version go1.9beta2 linux/amd64

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment