[][src]Function rayon_logs::subgraph

pub fn subgraph<OP, R>(work_type: &'static str, work_amount: usize, op: OP) -> R where
    OP: FnOnce() -> R, 

We tag all the tasks that op makes as one subgraph.

work_type is a str tag and work_amount an integer specifying the expected algorithmic cost (should not be zero). As we know the work and execution time we can compute an execution speed for each subgraph. When different graphs are tagged with the same tag we can then compare their speeds. Slow graphs will see their displayed colors darkened. You can also hover on tasks to display their speeds.

Example:

use rayon_logs::{join, subgraph, ThreadPoolBuilder};

fn manual_max(slice: &[u32]) -> u32 {
    if slice.len() < 200_000 {
        subgraph("max", slice.len(), || slice.iter().max().cloned().unwrap())
    } else {
        let middle = slice.len() / 2;
        let (left, right) = slice.split_at(middle);
        let (mleft, mright) = join(|| manual_max(left), || manual_max(right));
        std::cmp::max(mleft, mright)
    }
}

let v: Vec<u32> = (0..2_000_000).collect();
let pool = ThreadPoolBuilder::new()
    .num_threads(2)
    .build()
    .expect("building pool failed");
let max = pool.install(|| manual_max(&v));
assert_eq!(max, v.last().cloned().unwrap());

Using it we obtain the graph below. On the real file you can hover but javascript and toggle the display of the different tags but it is disabled with rustdoc so I downgraded the file for this display.