nikolaydubina / go-enum-encoding Goto Github PK
View Code? Open in Web Editor NEWGenerate Go enum encoding
License: MIT License
Generate Go enum encoding
License: MIT License
This is my follow up from r/golang Reddit I did some benchmarking.
Each unmarshal benchmark iteration parses all 5 values (4x 4-6 characters long and one <empty>
) and one bad value (4 characters long) ie. abcd
, bcdef
, cdefg
, defg
, <empty>
and zabc
.
Similar for each marshal benchmark iteration parses all 5 values.
Map lookup is significantly slower than loop for 5 items. Converting bytes to string and comparing is faster than comparing bytes using bytes.Equal because bytes.Equal converts both arguments to string anyway.
Array index is 30x faster than map lookup. Map lookup in MarshalText() and String() functions are even 40+% slower than UnmarshalText.
func BenchmarkMarshalText(b *testing.B) {
for i := 0; i < b.N; i++ {
_, _ = Abcd.MarshalText()
_, _ = Bcdef.MarshalText()
_, _ = Cdefg.MarshalText()
_, _ = Defg.MarshalText()
_, _ = UnknownType.MarshalText()
}
}
func BenchmarkUnmarshalText(b *testing.B) {
x := MarketType{}
for i := 0; i < b.N; i++ {
x.UnmarshalText([]byte("abcd"))
x.UnmarshalText([]byte("bcdef"))
x.UnmarshalText([]byte("cdefg"))
x.UnmarshalText([]byte("defg"))
x.UnmarshalText([]byte(""))
x.UnmarshalText([]byte("zabc"))
}
}
cpu: AMD Ryzen 9 7950X3D 16-Core Processor
BenchmarkMarshalText-32 19269684 62.31 ns/op 0 B/op 0 allocs/op
BenchmarkMarshalTextLookup-32 502871172 2.200 ns/op 0 B/op 0 allocs/op
BenchmarkMarshalTextLookupString-32 541060243 2.202 ns/op 0 B/op 0 allocs/op
BenchmarkString-32 20310391 57.20 ns/op 0 B/op 0 allocs/op
BenchmarkStringLookupString-32 439474542 2.646 ns/op 0 B/op 0 allocs/op
BenchmarkStringLookupBytes-32 100000000 10.97 ns/op 0 B/op 0 allocs/op
BenchmarkStringSwitch-32 372506850 3.955 ns/op 0 B/op 0 allocs/op
BenchmarkStringSwitchValue-32 262102232 3.888 ns/op 0 B/op 0 allocs/op
BenchmarkUnmarshalText-32 33958742 35.89 ns/op 0 B/op 0 allocs/op
BenchmarkUnmarshalTextLookup-32 38068413 31.15 ns/op 0 B/op 0 allocs/op
BenchmarkUnmarshalTextLookupString-32 52166524 23.68 ns/op 0 B/op 0 allocs/op
BenchmarkUnmarshalTextLookupStringAndConvert-32 31179402 38.46 ns/op 0 B/op 0 allocs/op
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.