pswaminathan at home in ~/uuidbench
$ gb test -v -bench=. -test.benchmem
uuids
testing: warning: no tests to run
PASS
BenchmarkPbormanParse-4 3000000 599 ns/op 80 B/op 5 allocs/op
BenchmarkPbormanDump-4 200000 6756 ns/op 1520 B/op 60 allocs/op
BenchmarkSatoriParse-4 1000000 1149 ns/op 240 B/op 5 allocs/op
BenchmarkSatoriDump-4 3000000 584 ns/op 240 B/op 5 allocs/op
Last active
August 27, 2019 19:45
-
-
Save pswaminathan/6d78c99dc9768f09019c to your computer and use it in GitHub Desktop.
Benchmarking Go (Golang) UUID Packages
pswaminathan at mm-mac-3325 in ~/uuidbench
$ gb test -v -bench=. -test.benchmem
uuids
testing: warning: no tests to run
PASS
BenchmarkPbormanParse-4 20000000 116 ns/op 16 B/op 1 allocs/op
BenchmarkPbormanDump-4 1000000 1347 ns/op 304 B/op 12 allocs/op
BenchmarkSatoriParse-4 10000000 219 ns/op 48 B/op 1 allocs/op
BenchmarkSatoriDump-4 20000000 112 ns/op 48 B/op 1 allocs/op
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package uuids | |
import ( | |
pb "github.com/pborman/uuid" | |
satori "github.com/satori/go.uuid" | |
"testing" | |
) | |
var ( | |
testStrings = []string{ | |
"7fb0533d-91a0-4d00-ad8e-37958e04acc2", | |
"3f5c5371-49f1-4500-a091-e472ac8a9ee2", | |
"e8365375-5608-4e00-9c83-68a11fab829e", | |
"640653a0-cad8-4200-b52c-8a59157874f7", | |
"640653a0-cad8-4200-b52c-8a59157874f7", | |
} | |
testPBs []pb.UUID | |
testSTs []satori.UUID | |
) | |
func init() { | |
testPBs = make([]pb.UUID, len(testStrings)) | |
testSTs = make([]satori.UUID, len(testStrings)) | |
for i, s := range testStrings { | |
testPBs[i] = pb.Parse(s) | |
testSTs[i] = satori.FromStringOrNil(s) | |
} | |
} | |
func BenchmarkPbormanParse(b *testing.B) { | |
for i := 0; i < b.N; i++ { | |
for _, s := range testStrings { | |
uuid := pb.Parse(s) | |
_ = uuid | |
} | |
} | |
} | |
func BenchmarkPbormanDump(b *testing.B) { | |
for i := 0; i < b.N; i++ { | |
for _, uuid := range testPBs { | |
s := uuid.String() | |
_ = s | |
} | |
} | |
} | |
func BenchmarkSatoriParse(b *testing.B) { | |
for i := 0; i < b.N; i++ { | |
for _, s := range testStrings { | |
uuid := satori.FromStringOrNil(s) | |
_ = uuid | |
} | |
} | |
} | |
func BenchmarkSatoriDump(b *testing.B) { | |
for i := 0; i < b.N; i++ { | |
for _, uuid := range testSTs { | |
s := uuid.String() | |
_ = s | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package uuids | |
import ( | |
pb "github.com/pborman/uuid" | |
satori "github.com/satori/go.uuid" | |
"testing" | |
) | |
var ( | |
testString = "640653a0-cad8-4200-b52c-8a59157874f7" | |
testPB pb.UUID | |
testST satori.UUID | |
) | |
func init() { | |
testPB = pb.Parse(testString) | |
testST = satori.FromStringOrNil(testString) | |
} | |
func BenchmarkPbormanParse(b *testing.B) { | |
for i := 0; i < b.N; i++ { | |
uuid := pb.Parse(testString) | |
_ = uuid | |
} | |
} | |
func BenchmarkPbormanDump(b *testing.B) { | |
for i := 0; i < b.N; i++ { | |
s := testPB.String() | |
_ = s | |
} | |
} | |
func BenchmarkSatoriParse(b *testing.B) { | |
for i := 0; i < b.N; i++ { | |
uuid := satori.FromStringOrNil(testString) | |
_ = uuid | |
} | |
} | |
func BenchmarkSatoriDump(b *testing.B) { | |
for i := 0; i < b.N; i++ { | |
s := testST.String() | |
_ = s | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
An update: here are the results of the benchmarks using the current and more maintained forks of both packages:
Results on a 2017 Macbook Pro with go 1.12.6. I´m doubtful about PbormanParse not doing any allocs but the rest doesn't seem to be biased:
go test -test.v -test.bench=. -test.benchmem goos: darwin goarch: amd64 pkg: uuids/uuids BenchmarkPbormanParse-4 50000000 34.5 ns/op 0 B/op 0 allocs/op BenchmarkPbormanDump-4 20000000 66.3 ns/op 48 B/op 1 allocs/op BenchmarkSatoriParse-4 20000000 121 ns/op 48 B/op 1 allocs/op BenchmarkSatoriDump-4 20000000 62.2 ns/op 48 B/op 1 allocs/op PASS