rust-itertools / itertools

Extra iterator adaptors, iterator methods, free functions, and macros.
https://docs.rs/itertools/
Apache License 2.0
2.72k stars 309 forks source link

Implement custom fold for ZipSlice #762

Closed Owen-CH-Leung closed 1 year ago

Owen-CH-Leung commented 1 year ago

As per discussion in #755 , this PR implements custom fold logic for ZipSlices<T, U> and create benchmark test to measure the performance gain compared with the default fold.

Running the zipdot i32 zipslices fold benchmark using the default fold logic, the time was time: [42.749 ns 43.163 ns 43.782 ns]

Running the zipdot i32 zipslices fold benchmark using the custom fold logic, the time was time: [42.523 ns 42.621 ns 42.737 ns]

Philippe-Cholet commented 1 year ago

I was gonna say I was surprised by the unsafe use, especially for such time win but ZipSlices is not part of the itertools library, it's only part of benches.

Owen-CH-Leung commented 1 year ago

Ahh yesss I misread. I thought it's under src when I was revising it. Thanks both for your comments. I'll continue to see if custom fold can be implemented in other iterators