James Beard d83e5801ac
Convert tests to Typescript, change require to import, and add named exports to modules (#2550)
* Converting bench.js and test.js to Typescript. Adding along as a named export as well as the default.

* Converting bench.js and test.js to Typescript and ESM import. Adding angle as a named export as well as the default.

* Converting bench.js and test.js to Typescript and ESM import. Adding area as a named export as well as the default.

* Making turf last-checks a bit more flexible as we will have a mix of JS and TS test files for a while.

* Converting bench.js and test.js to Typescript and ESM import, and adding named exports as well as the default export for modules:

bbox
bboxCliip
bboxPolygon
bearing
bezierSpline
booleanClockwise
booleanConcave
booleanContains
booleanCrosses
booleanDisjoint
booleanEqual
booleanIntersect
booleanOverlap
booleanParallel
booleanPointInPolygon
booleanPointOnLine
booleanTouches
booleanValid
booleanWithin

* Converting bench.js and test.js to Typescript and ESM import for remaining Typescript modules. Also adding named exports in addition to the default export for those same modules.

* Proceeding with migrating remaining tests to Typescript. Still a few to do - waiting for PR #2543 to merge first to avoid conflicts.

* Converting bench.js and test.js to Typescript and ESM import for some more Typescript modules (postponed until recent PRs merged). Also adding named exports in addition to the default export for those same modules.

* Banishing a couple more require() calls from module code.

* Retiring custom rollup typescript plugin. Problem it was designed to address probably fixed by a previous typescript upgrade. Removing redundant es5 checking script that hasn't been used for a while as well.
2023-12-05 19:04:54 +11:00

51 lines
1.6 KiB
TypeScript

import path from "path";
import { glob } from "glob";
import { loadJsonFileSync } from "load-json-file";
import Benchmark from "benchmark";
import { booleanParallel } from "./index";
/**
* Benchmark Results
*
* line1: 2.578ms
* line2: 0.137ms
* city-line: 0.096ms
* fiji: 0.073ms
* geometry: 0.123ms
* line1: 0.068ms
* line3-reverse: 0.065ms
* line3: 0.429ms
* resolute: 0.077ms
* segment1: 0.203ms
* segment2: 0.087ms
* segment3: 0.698ms
*
* line1 x 171,462 ops/sec ±2.03% (79 runs sampled)
* line2 x 160,366 ops/sec ±6.55% (80 runs sampled)
* city-line x 120,544 ops/sec ±8.47% (73 runs sampled)
* fiji x 101,793 ops/sec ±5.09% (75 runs sampled)
* geometry x 93,106 ops/sec ±7.57% (74 runs sampled)
* line1 x 102,175 ops/sec ±4.95% (80 runs sampled)
* line3-reverse x 129,695 ops/sec ±2.11% (82 runs sampled)
* line3 x 129,860 ops/sec ±2.32% (83 runs sampled)
* resolute x 136,275 ops/sec ±2.89% (79 runs sampled)
* segment1 x 193,214 ops/sec ±4.31% (76 runs sampled)
* segment2 x 205,418 ops/sec ±2.16% (83 runs sampled)
* segment3 x 212,381 ops/sec ±1.79% (83 runs sampled)
*/
const suite = new Benchmark.Suite("turf-boolean-parallel");
glob
.sync(path.join(__dirname, "test", "**", "*.geojson"))
.forEach((filepath) => {
const { name } = path.parse(filepath);
const geojson = loadJsonFileSync(filepath);
const [line1, line2] = geojson.features;
console.time(name);
booleanParallel(line1, line2);
console.timeEnd(name);
suite.add(name, () => booleanParallel(line1, line2));
});
suite.on("cycle", (e) => console.log(String(e.target))).run();