making a small crate just to benchmark pathfinding

This commit is contained in:
Dustin Carlino 2019-03-02 10:08:23 -08:00
parent 214e461601
commit a67b595df6
4 changed files with 73 additions and 3 deletions

View File

@ -3,6 +3,7 @@
members = [
"abstutil",
"analyze_code",
"benchmark_pathfinding",
"convert_osm",
"debug_initialmap",
"editor",

View File

@ -0,0 +1,14 @@
[package]
name = "benchmark_pathfinding"
version = "0.1.0"
authors = ["Dustin Carlino <dabreegster@gmail.com>"]
edition = "2018"
[dependencies]
abstutil = { path = "../abstutil" }
cpuprofiler = "0.0.3"
geom = { path = "../geom" }
map_model = { path = "../map_model" }
rand = "0.6.5"
rand_xorshift = "0.1.1"
structopt = "0.2"

View File

@ -0,0 +1,57 @@
use abstutil::Timer;
use geom::Distance;
use map_model::{Map, PathRequest, Pathfinder, Position};
use rand::seq::SliceRandom;
use rand::SeedableRng;
use rand_xorshift::XorShiftRng;
use structopt::StructOpt;
const RNG_SEED: u8 = 42;
const NUM_PATHS: usize = 150;
#[derive(StructOpt, Debug)]
#[structopt(name = "benchmark_pathfinding")]
struct Flags {
/// Map to load
#[structopt(name = "map")]
pub map: String,
/// Enable cpuprofiler?
#[structopt(long = "enable_profiler")]
pub enable_profiler: bool,
}
fn main() {
let flags = Flags::from_args();
let mut timer = Timer::new("benchmark pathfinding");
let mut rng = XorShiftRng::from_seed([RNG_SEED; 16]);
let map: Map = abstutil::read_binary(&flags.map, &mut timer).unwrap();
if flags.enable_profiler {
cpuprofiler::PROFILER
.lock()
.unwrap()
.start("./profile")
.unwrap();
}
println!(); // TODO Because Timer manages newlines poorly
timer.start_iter("compute paths", NUM_PATHS);
for _ in 0..NUM_PATHS {
timer.next();
let lane1 = map.all_lanes().choose(&mut rng).unwrap().id;
let lane2 = map.all_lanes().choose(&mut rng).unwrap().id;
Pathfinder::shortest_distance(
&map,
PathRequest {
start: Position::new(lane1, Distance::ZERO),
end: Position::new(lane2, Distance::ZERO),
can_use_bike_lanes: false,
can_use_bus_lanes: false,
},
);
}
if flags.enable_profiler {
cpuprofiler::PROFILER.lock().unwrap().stop().unwrap();
}
}

View File

@ -24,9 +24,7 @@ fn main() {
// TODO not the ideal way to distinguish what thing we loaded
let load = flags.sim_flags.load.clone();
let mut timer = Timer::new("setup headless");
let (map, mut sim, mut rng) = flags
.sim_flags
.load(None, &mut timer);
let (map, mut sim, mut rng) = flags.sim_flags.load(None, &mut timer);
if load.contains("data/raw_maps/") || load.contains("data/maps/") {
Scenario::small_run(&map).instantiate(&mut sim, &map, &mut rng, &mut timer);