kohensu and Carl Lerche
51e435b7e0
Improve performance of Buf::get_*() ( #195 )
...
The new implementation tries to get the data directly from bytes() (this is
possible most of the time) and if there is not enough data in bytes() use the
previous code: copy the needed bytes in a temporary buffer before returning
the data
Here the bench results:
Before After x-faster
get_f32::cursor 64 ns/iter (+/- 0) 20 ns/iter (+/- 0) 3.2
get_f32::tbuf_1 77 ns/iter (+/- 1) 34 ns/iter (+/- 0) 2.3
get_f32::tbuf_1_costly 87 ns/iter (+/- 0) 62 ns/iter (+/- 0) 1.4
get_f32::tbuf_2 151 ns/iter (+/- 18) 160 ns/iter (+/- 1) 0.9
get_f32::tbuf_2_costly 180 ns/iter (+/- 2) 187 ns/iter (+/- 2) 1.0
get_f64::cursor 67 ns/iter (+/- 0) 21 ns/iter (+/- 0) 3.2
get_f64::tbuf_1 80 ns/iter (+/- 0) 35 ns/iter (+/- 0) 2.3
get_f64::tbuf_1_costly 82 ns/iter (+/- 3) 60 ns/iter (+/- 0) 1.4
get_f64::tbuf_2 154 ns/iter (+/- 1) 164 ns/iter (+/- 0) 0.9
get_f64::tbuf_2_costly 170 ns/iter (+/- 2) 187 ns/iter (+/- 1) 0.9
get_u16::cursor 66 ns/iter (+/- 0) 20 ns/iter (+/- 0) 3.3
get_u16::tbuf_1 77 ns/iter (+/- 0) 35 ns/iter (+/- 0) 2.2
get_u16::tbuf_1_costly 85 ns/iter (+/- 2) 62 ns/iter (+/- 0) 1.4
get_u16::tbuf_2 147 ns/iter (+/- 0) 154 ns/iter (+/- 0) 1.0
get_u16::tbuf_2_costly 160 ns/iter (+/- 1) 177 ns/iter (+/- 0) 0.9
get_u32::cursor 64 ns/iter (+/- 0) 20 ns/iter (+/- 0) 3.2
get_u32::tbuf_1 77 ns/iter (+/- 0) 35 ns/iter (+/- 0) 2.2
get_u32::tbuf_1_costly 91 ns/iter (+/- 2) 63 ns/iter (+/- 0) 1.4
get_u32::tbuf_2 151 ns/iter (+/- 40) 157 ns/iter (+/- 0) 1.0
get_u32::tbuf_2_costly 162 ns/iter (+/- 0) 180 ns/iter (+/- 0) 0.9
get_u64::cursor 67 ns/iter (+/- 0) 20 ns/iter (+/- 0) 3.4
get_u64::tbuf_1 78 ns/iter (+/- 0) 35 ns/iter (+/- 1) 2.2
get_u64::tbuf_1_costly 87 ns/iter (+/- 1) 59 ns/iter (+/- 1) 1.5
get_u64::tbuf_2 154 ns/iter (+/- 0) 160 ns/iter (+/- 0) 1.0
get_u64::tbuf_2_costly 168 ns/iter (+/- 0) 184 ns/iter (+/- 0) 0.9
get_u8::cursor 64 ns/iter (+/- 0) 19 ns/iter (+/- 0) 3.4
get_u8::tbuf_1 77 ns/iter (+/- 0) 35 ns/iter (+/- 0) 2.2
get_u8::tbuf_1_costly 68 ns/iter (+/- 0) 51 ns/iter (+/- 0) 1.3
get_u8::tbuf_2 85 ns/iter (+/- 0) 43 ns/iter (+/- 0) 2.0
get_u8::tbuf_2_costly 75 ns/iter (+/- 0) 61 ns/iter (+/- 0) 1.2
get_u8::option 77 ns/iter (+/- 0) 59 ns/iter (+/- 0) 1.3
Improvement on the basic std::Cursor implementation are clearly visible.
Other implementations are specific to the bench tests and just map a static
slice. Different variant are:
- tbuf_1: only one call of 'bytes()' is needed.
- tbuf_2: two calls of 'bytes()' is needed to read more than one byte.
- _costly version are implemented with #[inline(never)] on 'bytes()',
'remaining()' and 'advance()'.
The cases that are slower (slightly) correspond to implementations that are not
really realistic: more than one byte is never possible in one time
2018-04-27 10:18:52 -07:00
Sean McArthur and Carl Lerche
ce79f0a268
Make Buf and BufMut usable as trait objects ( #186 )
...
- All the `get_*` and `put_*` methods that take `T: ByteOrder` have
a `where Self: Sized` bound added, so that they are only usable from
sized types. It was impossible to make `Buf` or `BufMut` into trait
objects before, so this change doesn't break anyone.
- Add `get_n_be`/`get_n_le`/`put_n_be`/`put_n_le` methods that can be
used on trait objects.
- Deprecate the export of `ByteOrder` and methods generic on it.
Fixes #163
2018-03-12 09:25:59 -07:00
Carl Lerche and GitHub
99fba239db
Tweak docs ( #76 )
2017-03-16 12:11:10 -07:00
Carl Lerche
06b94c55b0
Remove buf::Source in favor of buf::IntoBuf
...
The `Source` trait was essentially covering the same case as `IntoBuf`,
so remove it.
While technically a breaking change, this should not have any impact due
to:
1) There are no reverse dependencies that currently depend on `bytes`
2) Source was not supposed to be implemented externally
3) IntoBuf provides the same implementations as `Source`
Given these points, the change should be safe to apply.
2017-03-07 11:30:08 -08:00
Carl Lerche
d0142aa6da
Clarify API edge cases
2017-03-01 18:30:58 -08:00
Carl Lerche
94396162b2
Implement chain combinator for Buf
2017-03-01 14:22:53 -08:00
Carl Lerche
bb9bf7ee3e
Add vectored support to Buf and BufMut
2017-03-01 13:18:29 -08:00
Carl Lerche
4462056e26
Move stray impls into appropriate file
2017-03-01 13:15:11 -08:00
Carl Lerche
8fec8a92ad
Implement iterator adapter for Buf
2017-03-01 10:03:28 -08:00
Carl Lerche
4f8c565111
Implement FromBuf and Buf::collect
...
Enables collecting the contents of a `Buf` value into a relevant
concrete buffer implementation.
2017-03-01 09:30:13 -08:00
Carl Lerche
4466b75ae4
Split buf.rs into separate files
2017-02-28 15:21:20 -08:00