Skip to content

Commit

Permalink
bench.js updates (#1855)
Browse files Browse the repository at this point in the history
Looks like a few packages have fallen out of date, mostly cribbed any updates here from the corresponding test.js

Co-authored-by: Matt Fedderly <[email protected]>
  • Loading branch information
mfedderly and mfedderly authored Mar 16, 2020
1 parent b3b5284 commit 7e95c2d
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 31 deletions.
6 changes: 6 additions & 0 deletions packages/turf-boolean-within/bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ const within = require('./dist/js/index.js').default;
const suite = new Benchmark.Suite('turf-boolean-within');
glob.sync(path.join(__dirname, 'test', '**', '*.geojson')).forEach(filepath => {
const {name} = path.parse(filepath);

// don't test files that start with skip
if (/^skip/.test(name)) {
return;
}

const geojson = load.sync(filepath);
const [feature1, feature2] = geojson.features;
console.time(name);
Expand Down
4 changes: 2 additions & 2 deletions packages/turf-buffer/bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ const fixtures = fs.readdirSync(directory).map(filename => {
const suite = new Benchmark.Suite('turf-buffer');
for (const {name, geojson} of fixtures) {
console.time(name);
buffer(geojson, 50, 'miles');
buffer(geojson, 50, {units: 'miles'});
console.timeEnd(name);
suite.add(name, () => buffer(geojson, 50, 'miles'));
suite.add(name, () => buffer(geojson, 50, {units: 'miles'}));
}

suite
Expand Down
6 changes: 4 additions & 2 deletions packages/turf-combine/bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@ var p1 = polygon( [
[101.0,0.0],
[101.0,1.0],
[100.0,1.0],
[100.0,0.0]
[100.0,0.0],
[20.0,0.0]
]
])
var p2 = polygon([
[
[30.0,0.0],
[102.0,0.0],
[103.0,1.0]
[103.0,1.0],
[30.0,0.0]
]
])

Expand Down
4 changes: 2 additions & 2 deletions packages/turf-dissolve/bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const fixtures = fs.readdirSync(directory).map(filename => {
for (const {name, geojson} of fixtures) {
const propertyName = geojson.propertyName;
console.time(name);
dissolve(geojson, propertyName);
dissolve(geojson, {propertyName});
console.timeEnd(name);
}

Expand All @@ -33,7 +33,7 @@ for (const {name, geojson} of fixtures) {
const suite = new Benchmark.Suite('turf-dissolve');
for (const {name, geojson} of fixtures) {
const propertyName = geojson.propertyName;
suite.add(name, () => dissolve(geojson, propertyName));
suite.add(name, () => dissolve(geojson, {propertyName}));
}

suite
Expand Down
8 changes: 4 additions & 4 deletions packages/turf-interpolate/bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ const fixtures = fs.readdirSync(directory).map(filename => {
*/
const suite = new Benchmark.Suite('turf-interpolate');
for (const {name, geojson} of fixtures) {
const {property, cellSize, outputType, units, weight} = geojson.properties;

const options = geojson.properties;
const cellSize = options.cellSize;
console.time(name);
interpolate(geojson, cellSize, outputType, property, units, weight);
interpolate(geojson, cellSize, options);
console.timeEnd(name);
suite.add(name, () => interpolate(geojson, cellSize, outputType, property, units, weight));
suite.add(name, () => interpolate(geojson, cellSize, options));
}

suite
Expand Down
24 changes: 8 additions & 16 deletions packages/turf-mask/bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,16 @@ const directories = {
out: path.join(__dirname, 'test', 'out') + path.sep
};

let fixtures = fs.readdirSync(directories.in).map(folder => {
const files = {folder};
fs.readdirSync(path.join(directories.in, folder)).forEach(filename => {
const name = path.parse(filename).name;
files[name] = load.sync(path.join(directories.in, folder, filename));
});
return files;
let fixtures = fs.readdirSync(directories.in).map(filename => {
return {
name: path.parse(filename).name,
geojson: load.sync(path.join(directories.in, filename))
};
});
// const include = [
// 'basic',
// // 'overlapping',
// // 'feature-collection',
// // 'multipolygon'
// ];
// fixtures = fixtures.filter(fixture => include.indexOf(fixture.folder) !== -1);

for (const {folder, polygon, mask} of fixtures) {
suite.add(folder, () => turfMask(polygon, mask));
for (const {name, geojson} of fixtures) {
const [polygon, masking] = geojson.features;
suite.add(name, () => turfMask(polygon, masking));
}

suite
Expand Down
2 changes: 1 addition & 1 deletion packages/turf-point-grid/bench.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const Benchmark = require('benchmark');
const { polygon } = require('@turf/helpers');
const grid = require('./dist/js/index.js');
const grid = require('./dist/js/index.js').default;

var bbox = [-95, 30, -85, 40];
var mask = polygon([[[6.5, 44.6 ], [ 9.2, 44.8 ], [ 8.3, 46.4 ], [ 6.5, 44.6 ]]]);
Expand Down
4 changes: 2 additions & 2 deletions packages/turf-simplify/bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ for (const {name, geojson} of fixtures) {
tolerance = tolerance || 0.01;
highQuality = highQuality || false;
console.time(name);
simplify(geojson, tolerance, highQuality);
simplify(geojson, {tolerance, highQuality});
console.timeEnd(name);
}

Expand All @@ -58,7 +58,7 @@ for (const {name, geojson} of fixtures) {
let {tolerance, highQuality} = geojson.properties || {};
tolerance = tolerance || 0.01;
highQuality = highQuality || false;
suite.add(name, () => simplify(geojson, tolerance, highQuality));
suite.add(name, () => simplify(geojson, {tolerance, highQuality}));
}

suite
Expand Down
4 changes: 2 additions & 2 deletions packages/turf-transform-translate/bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const fixtures = fs.readdirSync(directory).map(filename => {
for (const {name, geojson} of fixtures) {
const {distance, direction, units, zTranslation} = geojson.properties || {};
console.time(name);
translate(geojson, distance, direction, units, zTranslation, true);
translate(geojson, distance, direction, {units, zTranslation, mutate: true});
console.timeEnd(name);
}

Expand All @@ -48,7 +48,7 @@ for (const {name, geojson} of fixtures) {
const suite = new Benchmark.Suite('turf-transform-translate');
for (const {name, geojson} of fixtures) {
const {distance, direction, units, zTranslation} = geojson.properties || {};
suite.add(name, () => translate(geojson, distance, direction, units, zTranslation));
suite.add(name, () => translate(geojson, distance, direction, {units, zTranslation}));
}

suite
Expand Down

0 comments on commit 7e95c2d

Please sign in to comment.