@@ -93,6 +93,69 @@ value := opt.UnwrapOr("default")
9393err := opt.EncodeMsgpack (encoder)
9494```
9595
96+ ## Benchmarking
97+
98+ Along with the approach supplied with go-option library pointer-based and slice-based approaches were benchmarked as well.
99+
100+ ### Empty base type (init + Get)
101+
102+ ```
103+ BenchmarkNoneInt/Typed-8 560566400 2.200 ns/op 0 B/op 0 allocs/op
104+ BenchmarkNoneInt/Generic-8 543332625 2.193 ns/op 0 B/op 0 allocs/op
105+ BenchmarkNoneInt/GenericPtr-8 487631254 2.474 ns/op 0 B/op 0 allocs/op
106+ BenchmarkNoneInt/GenericSlice-8 441513422 2.608 ns/op 0 B/op 0 allocs/op
107+ ```
108+
109+ ### Empty struct type (init + Get)
110+
111+ ```
112+ BenchmarkNoneStruct/Generic-8 415633797 2.884 ns/op 0 B/op 0 allocs/op
113+ BenchmarkNoneStruct/GenericPtr-8 331620082 3.580 ns/op 0 B/op 0 allocs/op
114+ BenchmarkNoneStruct/GenericSlice-8 387593746 3.115 ns/op 0 B/op 0 allocs/op
115+ BenchmarkNoneStruct/OptionalStruct-8 384845384 3.107 ns/op 0 B/op 0 allocs/op
116+ ```
117+
118+ ### Non-empty base type (init + Get)
119+
120+ ```
121+ BenchmarkSomeInt/Typed-8 499550200 2.231 ns/op 0 B/op 0 allocs/op
122+ BenchmarkSomeInt/Generic-8 321369986 3.491 ns/op 0 B/op 0 allocs/op
123+ BenchmarkSomeInt/GenericPtr-8 64221356 16.03 ns/op 8 B/op 1 allocs/op
124+ BenchmarkSomeInt/GenericSlice-8 71858188 16.53 ns/op 8 B/op 1 allocs/op
125+ ```
126+
127+ ### Non-empty struct type (init + Get)
128+
129+ ```
130+ BenchmarkSomeStruct/Generic-8 241312274 4.978 ns/op 0 B/op 0 allocs/op
131+ BenchmarkSomeStruct/GenericPtr-8 32534370 33.28 ns/op 24 B/op 1 allocs/op
132+ BenchmarkSomeStruct/GenericSlice-8 34119435 33.08 ns/op 24 B/op 1 allocs/op
133+ BenchmarkSomeStruct/OptionalStruct-8 358631294 3.407 ns/op 0 B/op 0 allocs/op
134+ ```
135+
136+ At this point we can see already that alternatives (based on pointer and slice) require allocations while go-option doesn't.
137+
138+ ### Encoding + Decoding of base type
139+
140+ ```
141+ BenchmarkEncodeDecodeInt/Typed-8 46089481 22.66 ns/op 0 B/op 0 allocs/op
142+ BenchmarkEncodeDecodeInt/Generic-8 10070619 119.6 ns/op 32 B/op 2 allocs/op
143+ BenchmarkEncodeDecodeInt/GenericSlice-8 17400481 66.24 ns/op 24 B/op 3 allocs/op
144+ BenchmarkEncodeDecodeInt/GenericPtr-8 20202076 58.14 ns/op 16 B/op 2 allocs/op
145+ ```
146+
147+ ### Encoding + Decoding of struct type
148+
149+ ```
150+ BenchmarkEncodeDecodeStruct/Generic-8 2304001 532.5 ns/op 67 B/op 3 allocs/op
151+ BenchmarkEncodeDecodeStruct/Generic[struct]-8 2172148 532.8 ns/op 67 B/op 3 allocs/op
152+ BenchmarkEncodeDecodeStruct/GenericSlice-8 2007445 587.4 ns/op 99 B/op 5 allocs/op
153+ BenchmarkEncodeDecodeStruct/GenericPtr-8 2071520 570.2 ns/op 75 B/op 4 allocs/op
154+ BenchmarkEncodeDecodeStruct/OptionalStruct-8 12816339 90.85 ns/op 3 B/op 1 allocs/op
155+ ```
156+
157+
158+
96159[ godoc-badge ] : https://pkg.go.dev/badge/github.com/tarantool/go-option.svg
97160[ godoc-url ] : https://pkg.go.dev/github.com/tarantool/go-option
98161[ actions-badge ] : https://github.com/tarantool/go-option/actions/workflows/testing.yaml/badge.svg
0 commit comments