| Crates.io | stack-buffer |
| lib.rs | stack-buffer |
| version | 0.3.0 |
| created_at | 2022-01-04 21:35:38.650259+00 |
| updated_at | 2022-04-03 03:16:03.140794+00 |
| description | Stack buffer provides alternatives to BufReader and BufWriter allocated on the stack instead of the heap. |
| homepage | |
| repository | https://github.com/SUPERCILEX/stack-buffer |
| max_upload_size | |
| id | 508067 |
| size | 57,560 |
Stack buffer provides alternatives to BufReader and BufWriter allocated on the stack instead of the heap. Its implementation is mostly copied from the standard library and changed only when required to use the stack.
The nightly compiler is required.
Add the following to your Cargo.toml file:
[dependencies]
stack-buffer = "0.1.0"
Replace Buf{Reader,Writer}::{new,with_capacity} with StackBuf{Reader,Writer}::<_, N>::new
where N is the allocated size on the stack.
StackBufReader always outperforms BufReader, typically by about 6%. Furthermore, the best stack
size appears to be 4096 for reads under 1 MB and 8192 for 1 MB+ reads.
StackBufWriter does not appear to offer a significant benefit over BufWriter and is sometimes
worse, but this may be due to benchmarking inaccuracies. 8192 appears to consistently be the best
stack size.