chunker
Minimalistic alternative to rayon’s par_iter/par_chunks + inner iteration + reduce for parallel processing of slices with progress bar by default.
Despite its name, this crate is really tiny: only 80 SLOC.
Usage
cargo add chunker
Call chunker::run or chunker::run_mut with these arguments:
items— slice of values to process in parallelconfig— configuration:thread_count,chunk_size,progress_bar,bar_stepinit— function to initialize a worker’s intermediate resultwork—Fnaccepting an individual value fromitemsand mutating the worker’s intermediate result (and/or mutating the value itself in the case ofrun_mut)gather—FnMutaccepting anmpsc::Receiverof workers’ intermediate results in random order and returns the final result (usually viareduce)
Examples
Sum of squares:
run
Simple parallel implementaion of word counting:
use ;
$ hyperfine 'target/release/examples/count_words <kjvbible_x10.txt'
Benchmark 1: target/release/examples/count_words <kjvbible_x10.txt
Time (mean ± σ): 78.7 ms ± 1.8 ms [User: 283.2 ms, System: 20.8 ms]
Range (min … max): 74.9 ms … 84.2 ms 36 runs