Skip to content

Commit

Permalink
add some benchmarking against proj4.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Rennzie committed Sep 22, 2023
1 parent 9fdd054 commit 3ffe482
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 4 deletions.
Binary file modified bun.lockb
Binary file not shown.
50 changes: 50 additions & 0 deletions examples/js/benchmark.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import Benchmark from 'benchmark';
const suite = new Benchmark.Suite();

import {Geodesy} from '../../pkg/node/index';
import proj4 from 'proj4';

const EPSG_27700 =
'+inv +proj=tmerc +lat_0=49 +lon_0=-2 +k_0=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy';
const stdPipelineDefinition = `
+proj=pipeline
+step ${EPSG_27700}
+step +proj=webmerc +lat_0=0 +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84
`;

const proj = proj4(EPSG_27700, 'EPSG:3857');
const geodesy = new Geodesy(stdPipelineDefinition);

const coords: number[][] = [];

const bounds = {
min: {x: -103976.3, y: -16703.87},
max: {x: 652897.98, y: 1199851.44},
};

for (let i = 0; i < 1_000_000; i++) {
const x = Math.random() * (bounds.max.x - bounds.min.x) + bounds.min.x;
const y = Math.random() * (bounds.max.y - bounds.min.y) + bounds.min.y;

coords.push([x, y]);
}

suite
.add('Proj4.js', () => {
const processed = coords.map(c => proj.forward(c));
})
.add('GeodesyWasm', () => {
const processedGeodesy = geodesy.forward(coords);
})
.on('cycle', (event: any) => {
const benchmark = event.target;

console.log(benchmark.toString());
})
.on('complete', (event: any) => {
const suite = event.currentTarget;
const fastestOption = suite.filter('fastest').map('name');

console.log(`The fastest option is ${fastestOption}`);
})
.run();
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
"eslint": "^8.46.0",
"eslint-config-prettier": "^9.0.0",
"prettier": "^3.0.1",
"typescript": "^5.1.6"
},
"dependencies": {
"commander": "^11.0.0"
"typescript": "^5.1.6",
"@types/benchmark": "^2.1.3",
"@types/proj4": "^2.5.2",
"benchmark": "^2.1.4",
"commander": "^11.0.0",
"proj4": "^2.9.0"
}
}

0 comments on commit 3ffe482

Please sign in to comment.