Skip to content

Commit 01fb0b7

Browse files
committed
add benchmark and todo to readme
1 parent 8aadf74 commit 01fb0b7

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

README.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,71 @@ Note that it is allowed to pass to the `PutXxx` functions objects that have been
2828
rp := httputil.NewSingleHostReverseProxy(target)
2929
rp.BufferPool = bytespool.GetBufferPool(32*1024)
3030
```
31+
32+
## Benchmarks
33+
34+
There is a small set of benchmarks you can run with `make bench` (you need to have [`benchstat`](https://golang.org/x/perf/cmd/benchstat) on your `PATH`), from which you can validate that in steady state no allocations are performed even for `[]byte`:
35+
36+
```
37+
name time/op
38+
GetBytesSlice-12 8.56ns ±14%
39+
GetBytesSliceSemiStatic-12 8.26ns ±14%
40+
GetBytesSliceStatic-12 8.19ns ±16%
41+
GetBytesSlicePtr-12 5.18ns ±23%
42+
GetBytesSlicePtrSemiStatic-12 4.74ns ±22%
43+
GetBytesSlicePtrStatic-12 4.74ns ±22%
44+
GetBytesBuffer-12 3.64ns ± 8%
45+
GetBytesBufferSemiStatic-12 3.18ns ± 5%
46+
GetBytesBufferStatic-12 3.12ns ± 5%
47+
GetBufioReader-12 5.82ns ± 7%
48+
GetBufioReaderSemiStatic-12 5.45ns ±10%
49+
GetBufioReaderStatic-12 5.39ns ± 6%
50+
GetBufioWriter-12 4.02ns ± 2%
51+
GetBufioWriterSemiStatic-12 3.73ns ± 4%
52+
GetBufioWriterStatic-12 3.56ns ± 3%
53+
54+
name alloc/op
55+
GetBytesSlice-12 0.00B
56+
GetBytesSliceSemiStatic-12 0.00B
57+
GetBytesSliceStatic-12 0.00B
58+
GetBytesSlicePtr-12 0.00B
59+
GetBytesSlicePtrSemiStatic-12 0.00B
60+
GetBytesSlicePtrStatic-12 0.00B
61+
GetBytesBuffer-12 0.00B
62+
GetBytesBufferSemiStatic-12 0.00B
63+
GetBytesBufferStatic-12 0.00B
64+
GetBufioReader-12 0.00B
65+
GetBufioReaderSemiStatic-12 0.00B
66+
GetBufioReaderStatic-12 0.00B
67+
GetBufioWriter-12 0.00B
68+
GetBufioWriterSemiStatic-12 0.00B
69+
GetBufioWriterStatic-12 0.00B
70+
71+
name allocs/op
72+
GetBytesSlice-12 0.00
73+
GetBytesSliceSemiStatic-12 0.00
74+
GetBytesSliceStatic-12 0.00
75+
GetBytesSlicePtr-12 0.00
76+
GetBytesSlicePtrSemiStatic-12 0.00
77+
GetBytesSlicePtrStatic-12 0.00
78+
GetBytesBuffer-12 0.00
79+
GetBytesBufferSemiStatic-12 0.00
80+
GetBytesBufferStatic-12 0.00
81+
GetBufioReader-12 0.00
82+
GetBufioReaderSemiStatic-12 0.00
83+
GetBufioReaderStatic-12 0.00
84+
GetBufioWriter-12 0.00
85+
GetBufioWriterSemiStatic-12 0.00
86+
GetBufioWriterStatic-12 0.00
87+
```
88+
89+
## Developing
90+
91+
Most of the code is in `gen/main.go`. You can run `make generate` to generate `bytespool.go`.
92+
93+
## TODO
94+
95+
- Split low-level APIs in a separate package
96+
- Ensure that users of the low-level API are not forced to compile also the high-level APIs
97+
- Define BufferPool-like interfaces for all objects (e.g. BytesBufferPool)
98+
- Provide non-singleton pools

0 commit comments

Comments
 (0)