-
Notifications
You must be signed in to change notification settings - Fork 320
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3e1a0c4
commit 98e9ee1
Showing
5 changed files
with
2,728 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#![feature(test)] | ||
|
||
extern crate petgraph; | ||
extern crate test; | ||
|
||
use petgraph::prelude::*; | ||
use std::cmp::{max, min}; | ||
use test::Bencher; | ||
|
||
use petgraph::algo::hamiltonian_circuits_directed; | ||
|
||
#[bench] | ||
fn hamiltonian_circuits_directed_bench(bench: &mut Bencher) { | ||
static NODE_COUNT: usize = 10; | ||
let mut g = Graph::new(); | ||
let nodes: Vec<NodeIndex<_>> = (0..NODE_COUNT).into_iter().map(|i| g.add_node(i)).collect(); | ||
for i in 0..NODE_COUNT { | ||
let n1 = nodes[i]; | ||
let neighbour_count = i % 8 + 3; | ||
let j_from = max(0, i as i32 - neighbour_count as i32 / 2) as usize; | ||
let j_to = min(NODE_COUNT, j_from + neighbour_count); | ||
for j in j_from..j_to { | ||
let n2 = nodes[j]; | ||
g.add_edge(n1, n2, ()); | ||
} | ||
} | ||
|
||
bench.iter(|| { | ||
let _circuit = hamiltonian_circuits_directed(&g).next(); | ||
}); | ||
} |
Oops, something went wrong.