• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

vigna / webgraph-rs / 17735521500

15 Sep 2025 01:54PM UTC coverage: 49.961% (-0.03%) from 49.987%
17735521500

push

github

web-flow
Merge pull request #137 from progval/fix-compil

bench_unit_transpose: Fix compilation

3888 of 7782 relevant lines covered (49.96%)

23960578.28 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/webgraph/examples/bench_unit_transpose.rs
1
/*
2
 * SPDX-FileCopyrightText: 2023 Inria
3
 * SPDX-FileCopyrightText: 2023 Sebastiano Vigna
4
 *
5
 * SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
6
 */
7

8
#![allow(clippy::type_complexity)]
9

10
use std::hint::black_box;
11

12
use anyhow::Result;
13
use clap::Parser;
14
use dsi_bitstream::dispatch::factory::CodesReaderFactoryHelper;
15
use dsi_bitstream::prelude::*;
16
use dsi_progress_logger::prelude::*;
17
use lender::prelude::*;
18
use std::path::PathBuf;
19
use tempfile::Builder;
20
use webgraph::graphs::arc_list_graph::{self, ArcListGraph};
21
use webgraph::utils::sort_pairs::{BatchIterator, KMergeIters};
22
use webgraph::{prelude::*, transform};
23

24
#[derive(Parser, Debug)]
25
#[command(about = "Benchmark direct transposition and labeled transposition on a unit graph.", long_about = None)]
26
struct Args {
27
    /// The basename of the graph.
28
    basename: PathBuf,
29
}
30

31
pub fn transpose(
32
    graph: &impl SequentialGraph,
33
    batch_size: usize,
34
) -> Result<Left<ArcListGraph<impl Iterator<Item = (usize, usize, ())> + Clone>>> {
35
    let dir = Builder::new().prefix("bench_unit_transpose").tempdir()?;
36
    let mut sorted = SortPairs::new(batch_size, dir.path())?;
37

38
    let mut pl = ProgressLogger::default();
39
    pl.item_name("node")
40
        .expected_updates(Some(graph.num_nodes()));
41
    pl.start("Creating batches...");
42
    // create batches of sorted edges
43
    for_! ( (src, succ) in graph.iter() {
44
        for dst in succ {
45
            sorted.push(dst, src)?;
46
        }
47
        pl.light_update();
48
    });
49
    // merge the batches
50
    let map: fn((usize, usize, ())) -> (usize, usize) = |(src, dst, _)| (src, dst);
51
    let sorted = arc_list_graph::ArcListGraph::new(graph.num_nodes(), sorted.iter()?.map(map));
52
    pl.done();
53

54
    Ok(sorted)
55
}
56

57
fn bench_impl<E: Endianness>(args: Args) -> Result<()>
58
where
59
    MmapHelper<u32>: CodesReaderFactoryHelper<E>,
60
{
61
    let graph = webgraph::graphs::bvgraph::sequential::BvGraphSeq::with_basename(args.basename)
×
62
        .endianness::<E>()
63
        .load()?;
64

65
    let unit = UnitLabelGraph(&graph);
×
66

67
    for _ in 0..10 {
×
68
        let mut pl = ProgressLogger::default();
×
69
        pl.start("Transposing standard graph...");
×
70

71
        let mut iter = transpose(&graph, 10_000_000)?.iter();
×
72
        while let Some((x, s)) = iter.next() {
×
73
            black_box(x);
×
74
            for i in s {
×
75
                black_box(i);
×
76
            }
77
        }
78
        pl.done_with_count(graph.num_nodes());
×
79

80
        pl.start("Transposing unit graph...");
×
81
        let mut iter = Left(transform::transpose_labeled(&unit, 10_000_000, (), ())?).iter();
×
82
        while let Some((x, s)) = iter.next() {
×
83
            black_box(x);
×
84
            for i in s {
×
85
                black_box(i);
×
86
            }
87
        }
88
        pl.done_with_count(unit.num_nodes());
×
89
    }
90

91
    Ok(())
×
92
}
93

94
pub fn main() -> Result<()> {
95
    let args = Args::parse();
96

97
    env_logger::builder()
98
        .filter_level(log::LevelFilter::Info)
99
        .try_init()?;
100

101
    match get_endianness(&args.basename)?.as_str() {
102
        #[cfg(any(
103
            feature = "be_bins",
104
            not(any(feature = "be_bins", feature = "le_bins"))
105
        ))]
106
        BE::NAME => bench_impl::<BE>(args),
107
        #[cfg(any(
108
            feature = "le_bins",
109
            not(any(feature = "be_bins", feature = "le_bins"))
110
        ))]
111
        LE::NAME => bench_impl::<LE>(args),
112
        e => panic!("Unknown endianness: {}", e),
113
    }
114
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc