Skip to content

Commit

Permalink
random and iter tests with 10 reps
Browse files Browse the repository at this point in the history
  • Loading branch information
ciminilorenzo committed Mar 8, 2024
1 parent 9bd4d9d commit 8bf57fc
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 26 deletions.
16 changes: 11 additions & 5 deletions script.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@
webgraph_rs_dir = sys.argv[3]

# Check all needed directories are present before actually starting the script.
if not os.path.isdir(graphs_dir) or not os.path.isdir(compressed_graphs_dir):
print(f"{graphs_dir} doesn't exist. Usage is: \n <graphs' dir> <new graphs' dir> <webgraph-rs dir>")
if not os.path.isdir(graphs_dir):
print(f"{graphs_dir} it not a directory.\nUsage is: python script.py <graphs' dir> <new graphs' dir> <webgraph-rs dir>")
exit(1)

if not os.path.isdir(webgraph_rs_dir):
print(f"{webgraph_rs_dir} Usage is: \n <graphs' dir> <new graphs' dir> <webgraph-rs dir>")
print(f"{webgraph_rs_dir} is not a directory.\nUsage is: python script.py <graphs' dir> <new graphs' dir> <webgraph-rs dir>")
exit(1)

if not os.path.isdir(compressed_graphs_dir):
print(f"{compressed_graphs_dir} is not a directory.\nUsage is: python script.py <graphs' dir> <new graphs' dir> <webgraph-rs dir>")
exit(1)

# Check all needed files are present before actually starting the script.
Expand Down Expand Up @@ -101,7 +105,8 @@
f"{compressed_graphs_dir}{graph}-hc",
], stdout=subprocess.PIPE))

sequential_access_speed.append(float(sequential_speed.stdout.decode('utf-8')))
sequential_speed = sorted([float(speed) for speed in sequential_speed.stdout.decode('utf-8').split("\n") if speed != ''])
sequential_access_speed.append(sequential_speed[len(sequential_speed) // 2])

# The random speed test is performed by running random_access_bvtest on the compressed graph.
print(f"Starting random speed test of {graph}")
Expand All @@ -110,7 +115,8 @@
f"{compressed_graphs_dir}{graph}",
], stdout=subprocess.PIPE))

random_access_speed.append(float(random_speed.stdout.decode('utf-8')))
random_speed = sorted([float(speed) for speed in random_speed.stdout.decode('utf-8').split("\n") if speed != ''])
random_access_speed.append(random_speed[len(random_speed) // 2])

with open('results.csv', 'w', encoding='UTF8', newline='') as f:
writer = csv.writer(f)
Expand Down
26 changes: 14 additions & 12 deletions src/bin/random_access_bvtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,20 @@ pub fn main() -> Result<()> {
.expected_updates(Some(RANDOM_TEST_SAMPLES as usize));
pl.start("Starting random-access speed test...");

// Random-access speed test
let mut rng = SmallRng::seed_from_u64(0);
let mut c: u64 = 0;
let num_nodes = graph.num_nodes();
let random_nodes = (0..RANDOM_TEST_SAMPLES).map(|_| rng.gen_range(0..num_nodes));
let start = std::time::Instant::now();
for node in random_nodes {
c += black_box(graph.successors(node).count() as u64);
pl.update();
for _ in 0..10 {
// Random-access speed test
let mut rng = SmallRng::seed_from_u64(0);
let mut c: u64 = 0;
let num_nodes = graph.num_nodes();
let random_nodes = (0..RANDOM_TEST_SAMPLES).map(|_| rng.gen_range(0..num_nodes));
let start = std::time::Instant::now();
for node in random_nodes {
c += black_box(graph.successors(node).count() as u64);
pl.update();
}
pl.done_with_count(c as usize);

println!("{:.2}", start.elapsed().as_nanos() / c as u128);
}
pl.done_with_count(c as usize);

println!("{:.2}", start.elapsed().as_nanos() / c as u128);
Ok(())
}
17 changes: 8 additions & 9 deletions src/bin/seq_access_bvtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,14 @@ pub fn main() -> anyhow::Result<()> {
.expected_updates(Some(graph.num_nodes()));
pl.start("Starting sequential-access speed test...");

let mut c: u64 = 0;
let start = std::time::Instant::now();
let mut iter = graph.iter();
while let Some((_, succ)) = iter.next() {
c += succ.into_iter().count() as u64;
for _ in 0..10 {
let mut c: u64 = 0;
let start = std::time::Instant::now();
let mut iter = graph.iter();
while let Some((_, succ)) = iter.next() {
c += succ.into_iter().count() as u64;
}
println!("{}", (start.elapsed().as_secs_f64() / c as f64) * 1e9);
}
println!("{}", (start.elapsed().as_secs_f64() / c as f64) * 1e9);

assert_eq!(c, graph.num_arcs_hint().unwrap());

Ok(())
}

0 comments on commit 8bf57fc

Please # to comment.