Skip to content

Commit

Permalink
Add benchmark target to Makefile and save timings
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMarex committed Apr 5, 2016
1 parent efe6faa commit 54ee76b
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 12 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ stxxl.errlog
/test/profile.lua
/test/cache
/test/speeds.csv
/test/data/monaco.*
node_modules

# Deprecated config file #
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ script:
- ./util-tests
- popd
- npm test
- make -C test/data
- make -C test/data benchmark
- mkdir example/build && pushd example/build
- cmake ..
- make
Expand Down
61 changes: 61 additions & 0 deletions scripts/poly2req.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/env node

'use strict';

let fs = require('fs');

let NUM_REQUEST = 1000;
let NUM_COORDS = 2;
let url_template = "http://127.0.0.1:5000/viaroute?{coords}&alt=false";
let coord_template = "loc={lat},{lon}";
let coords_separator = "&";
//let url_template = "http://127.0.0.1:5000/route/v1/driving/{coords}?steps=false&alternatives=false";
//let coord_template = "{lon},{lat}";
//let coords_separator = ";";

let monaco_poly_path = process.argv[2];
let poly_data = fs.readFileSync(monaco_poly_path, 'utf-8');

// lets assume there is only one ring
// cut of name and ring number and the two END statements
let coordinates = poly_data.split('\n')
.filter((l) => l != '')
.slice(2, -2).map((coord_line) => coord_line.split(' ')
.filter((elem) => elem != ''))
.map((coord) => [parseFloat(coord[0]), parseFloat(coord[1])]);

var sw = [Number.MAX_VALUE, Number.MAX_VALUE];
var ne = [Number.MIN_VALUE, Number.MIN_VALUE];

coordinates.forEach((c) => {
sw[0] = Math.min(sw[0], c[0]);
sw[1] = Math.min(sw[1], c[1]);
ne[0] = Math.max(ne[0], c[0]);
ne[1] = Math.max(ne[1], c[1]);
});

// Yes this an own seeded random number generator because its only a few lines
var seed = 0x1337;
function seededRandom(min, max) {
seed = (seed * 9301 + 49297) % 233280;
var rnd = seed / 233280;
return min + rnd * (max - min);
}

function getRandomCoordinate() {
let lon = seededRandom(sw[0], ne[0]);
let lat = seededRandom(sw[1], ne[1]);
return [lon, lat];
}

for (var i = 0; i < NUM_REQUEST; ++i)
{
var coords = [];
for (var j = 0; j < NUM_COORDS; ++j)
{
coords.push(getRandomCoordinate());
}
let coords_string = coords.map((c) => coord_template.replace("{lon}", c[0]).replace("{lat}", c[1])).join(coords_separator);
console.log(url_template.replace("{coords}", coords_string));
}

12 changes: 12 additions & 0 deletions scripts/timer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

TIMINGS_FILE=/tmp/osrm.timings
NAME=$1
CMD=${@:2}
START=$(date "+%s.%N")
/bin/bash -c "$CMD"
END=$(date "+%s.%N")
TIME="$(echo "$END - $START" | bc)s"
NEW_ENTRY="$NAME\t$TIME\t$(date -Iseconds)"

echo -e "$NEW_ENTRY" >> $TIMINGS_FILE
47 changes: 36 additions & 11 deletions test/data/Makefile
Original file line number Diff line number Diff line change
@@ -1,29 +1,54 @@
MONACO_URL:=https://s3.amazonaws.com/mapbox/osrm/testing/monaco.osm.pbf
DATA_NAME:=monaco
DATA_URL:=https://s3.amazonaws.com/mapbox/osrm/testing/$(DATA_NAME).osm.pbf
DATA_POLY_URL:=https://s3.amazonaws.com/mapbox/osrm/testing/$(DATA_NAME).poly
TOOL_ROOT:=../../build
PROFILE_ROOT:=../../profiles
SCRIPT_ROOT:=../../scripts
OSRM_EXTRACT:=$(TOOL_ROOT)/osrm-extract
OSRM_CONTRACT:=$(TOOL_ROOT)/osrm-contract
OSRM_ROUTED:=$(TOOL_ROOT)/osrm-routed
POLY2REQ:=$(SCRIPT_ROOT)/poly2req.js
TIMER:=$(SCRIPT_ROOT)/timer.sh
PROFILE:=$(PROFILE_ROOT)/car.lua

all: monaco.osrm.hsgr
all: $(DATA_NAME).osrm.hsgr

clean:
rm monaco.*
rm $(DATA_NAME).*

monaco.osm.pbf:
wget $(MONACO_URL) -O monaco.osm.pbf
$(DATA_NAME).osm.pbf:
wget $(DATA_URL) -O $(DATA_NAME).osm.pbf

monaco.osrm: monaco.osm.pbf $(PROFILE) $(OSRM_EXTRACT)
$(DATA_NAME).poly:
wget $(DATA_POLY_URL) -O $(DATA_NAME).poly

$(DATA_NAME).osrm: $(DATA_NAME).osm.pbf $(DATA_NAME).poly $(PROFILE) $(OSRM_EXTRACT)
@echo "Verifiyng data file integrity..."
md5sum -c data.md5sum
@echo "Running osrm-extract..."
$(OSRM_EXTRACT) monaco.osm.pbf -p $(PROFILE)
$(TIMER) "osrm-extract" $(OSRM_EXTRACT) $(DATA_NAME).osm.pbf -p $(PROFILE)

monaco.osrm.hsgr: monaco.osrm $(PROFILE) $(OSRM_CONTRACT)
$(DATA_NAME).osrm.hsgr: $(DATA_NAME).osrm $(PROFILE) $(OSRM_CONTRACT)
@echo "Running osrm-contract..."
$(OSRM_CONTRACT) monaco.osrm
$(TIMER) "osrm-contract" $(OSRM_CONTRACT) $(DATA_NAME).osrm

$(DATA_NAME).requests: $(DATA_NAME).poly
$(POLY2REQ) $(DATA_NAME).poly > $(DATA_NAME).requests

osrm-routed.pid: $(DATA_NAME).osrm.hsgr
@/bin/sh -c '$(OSRM_ROUTED) $(DATA_NAME).osrm& echo "$$!" > osrm-routed.pid'
sleep 1

benchmark: $(DATA_NAME).requests osrm-routed.pid
@echo "Running benchmark..."
$(TIMER) "queries" "cat $(DATA_NAME).requests | xargs curl &> /dev/null"
@cat osrm-routed.pid | xargs kill
@rm osrm-routed.pid
@echo "**** timings ***"
@cat /tmp/osrm.timings
@echo "****************"

checksum:
md5sum monaco.osm.pbf > data.md5sum
md5sum $(DATA_NAME).osm.pbf $(DATA_NAME).poly > data.md5sum

.PHONY: clean checksum
.PHONY: clean checksum benchmark
1 change: 1 addition & 0 deletions test/data/data.md5sum
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
2b8dd9343d5e615afc9c67bcc7028a63 monaco.osm.pbf
b0788991ab3791d53c1c20b6281f81ad monaco.poly

0 comments on commit 54ee76b

Please sign in to comment.