Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 28 additions & 30 deletions test/nodejs/benchmark.js
Original file line number Diff line number Diff line change
@@ -1,55 +1,53 @@
// Performance benchmarking tool for OSRM routing services
import OSRM from '../../lib/index.js';
import { performance, createHistogram } from 'node:perf_hooks';
import { mld_data_path } from './constants.js';
import { OSRM, mld_data_path } from './constants.js';

// usage: node test/nodejs/benchmark.js berlin-latest.osrm 13.388860,52.517037;13.385983,52.496891
const args = process.argv.slice(2);
const path = args[0] || mld_data_path;

// Parse semicolon-separated waypoints from command line arguments
function parseWaypoints(waypoints) {
if (waypoints == undefined) {
return undefined;
}
return waypoints.split(';').map((waypoint) => {
const [lon, lat] = waypoint.split(',');
return [parseFloat(lon), parseFloat(lat)];
});
if (waypoints == undefined) {
return undefined;
}
return waypoints.split(';').map((waypoint) => {
const [lon, lat] = waypoint.split(',');
return [parseFloat(lon), parseFloat(lat)];
});
}
const waypoints = parseWaypoints(args[1]) || [[7.41337, 43.72956],[7.41546, 43.73077]];
const osrm = new OSRM({path, algorithm: 'MLD'});

// Promisify the OSRM route callback for async/await usage
async function route(coordinates) {
const promise = new Promise((resolve, reject) => {
osrm.route({coordinates, steps: true, overview: 'full'}, (err, result) => {
if (err) {
reject(err);
} else {
resolve(result);
}
});
const promise = new Promise((resolve, reject) => {
osrm.route({coordinates, steps: true, overview: 'full'}, (err, result) => {
if (err) {
reject(err);
} else {
resolve(result);
}
});
return promise;
});
return promise;
}

async function benchmark() {
// warmup
await route(waypoints);
// warmup
await route(waypoints);

const performanceHistorgram = createHistogram();
const performanceHistorgram = createHistogram();

for (let i = 0; i < 1000; i++) {
const start = performance.now();
await route(waypoints);
const end = performance.now();
// record result in microseconds
performanceHistorgram.record(Math.ceil((end - start) * 1000));
}
for (let i = 0; i < 1000; i++) {
const start = performance.now();
await route(waypoints);
const end = performance.now();
// record result in microseconds
performanceHistorgram.record(Math.ceil((end - start) * 1000));
}


console.log(performanceHistorgram);
console.log(performanceHistorgram);
}
benchmark();

43 changes: 20 additions & 23 deletions test/nodejs/constants.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,29 @@
import path from 'path';
import { fileURLToPath } from 'url';

// Constants and fixtures for nodejs tests on our Monaco dataset.
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
import path from 'node:path';
import { pathToFileURL } from 'node:url';
import { osrm } from '../../features/support/fbresult_generated.js';

// Somewhere in Monaco
// http://www.openstreetmap.org/#map=18/43.73185/7.41772
export const three_test_coordinates = [[7.41337, 43.72956],
[7.41546, 43.73077],
[7.41862, 43.73216]];
[7.41546, 43.73077],
[7.41862, 43.73216]];

export const two_test_coordinates = three_test_coordinates.slice(0, 2);

export const test_tile = {'at': [17059, 11948, 15], 'size': 159125};

// Test files generated by the routing engine; check test/data
let data_path, mld_data_path, test_memory_path;

if (process.env.OSRM_DATA_PATH !== undefined) {
data_path = path.join(path.resolve(process.env.OSRM_DATA_PATH), "ch/monaco.osrm");
mld_data_path = path.join(path.resolve(process.env.OSRM_DATA_PATH), "mld/monaco.osrm");
test_memory_path = path.join(path.resolve(process.env.OSRM_DATA_PATH), "test_memory");
console.log('Setting custom data path to ' + data_path);
} else {
data_path = path.resolve(path.join(__dirname, "../data/ch/monaco.osrm"));
mld_data_path = path.resolve(path.join(__dirname, "../data/mld/monaco.osrm"));
test_memory_path = path.resolve(path.join(__dirname, "../data/test_memory"));
}

export { data_path, mld_data_path, test_memory_path };
const install_dir = process.env.OSRM_NODEJS_INSTALL_DIR || '.';
const test_data_dir = process.env.OSRM_DATA_PATH || process.env.OSRM_TEST_DATA_DIR || 'test/data';

console.log(`# Setting installation path to: ${test_data_dir}`);
console.log(`# Setting custom data path to: ${test_data_dir}`);

const data_path = path.resolve(path.join(test_data_dir, 'ch', 'monaco.osrm'));
const mld_data_path = path.resolve(path.join(test_data_dir, 'mld', 'monaco.osrm'));
const test_memory_path = path.resolve(path.join(test_data_dir, 'test_memory'));

const { default: OSRM, version } = await import(pathToFileURL(path.join(install_dir, 'lib', 'index.js')).href);

const FBResult = osrm.engine.api.fbresult.FBResult;

export { OSRM, FBResult, version, data_path, mld_data_path, test_memory_path };
Loading
Loading