You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
read_all_bytes time: [55.840 µs 55.882 µs 55.924 µs]
change: [-0.3273% -0.2149% -0.1034%] (p = 0.00 < 0.05)
Change within noise threshold.
Found 3 outliers among 100 measurements (3.00%)
2 (2.00%) low mild
1 (1.00%) high mild
read_all time: [57.742 µs 57.794 µs 57.856 µs]
change: [+0.6835% +0.8126% +0.9457%] (p = 0.00 < 0.05)
Change within noise threshold.
Found 1 outliers among 100 measurements (1.00%)
1 (1.00%) low mild
count time: [4.2984 µs 4.2997 µs 4.3013 µs]
change: [+0.2270% +0.2768% +0.3244%] (p = 0.00 < 0.05)
Change within noise threshold.
Found 3 outliers among 100 measurements (3.00%)
2 (2.00%) high mild
1 (1.00%) high severe
The result shows that read_all takes nearly 14 times longer than count on my machine (CPU: x86-64 2.10GHz 80threads).
Dig into the code:
// read_allletmut res = capacity.map_or_else(Vec::new,Vec::with_capacity);loop{if reader.end(){break;}let val = <T>::from_reader_with_ctx(reader, ctx)?;
res.push(val);}Ok(res)// countletmut res = capacity.map_or_else(Vec::new,Vec::with_capacity);let start_read = reader.bits_read;loop{let val = <T>::from_reader_with_ctx(reader, ctx)?;
res.push(val);// I replace the original code here
count -= 1;if count == 0{break;}}Ok(res)
The code is not very different; there is just one check, count == 0, and the other, reader.end(). I wonder whether reader.end() can be improved to perform better.
I also wonder whether it is possible to read an exact number of bytes instead of the loop for Vec<u8>. But I haven't figured out how to specialize the trait implementation for Vec<u8> over the generic Vec<T>.
The text was updated successfully, but these errors were encountered:
I also wonder whether it is possible to read an exact number of bytes instead of the loop for Vec. But I haven't figured out how to specialize the trait implementation for Vec over the generic Vec.
I think the solution here might just be the use a BufReaader, which will read larger amounts at a time instead of one byte. Syscalls wise at least.
I just found that
read_all
seems to perform worse thancount
. So, I'm opening this issue to see whether there is room for improvement.The rust code I used to test is as follows. I defined two simple structs that only wrap
Vec<u8>
and use Deku to read[u8; 1500]
into these structs.The output of criterion:
The result shows that
read_all
takes nearly 14 times longer thancount
on my machine (CPU: x86-64 2.10GHz 80threads).Dig into the code:
The code is not very different; there is just one check,
count == 0,
and the other,reader.end()
. I wonder whetherreader.end()
can be improved to perform better.I also wonder whether it is possible to read an exact number of bytes instead of the loop for
Vec<u8>
. But I haven't figured out how to specialize the trait implementation forVec<u8>
over the genericVec<T>
.The text was updated successfully, but these errors were encountered: