Skip to content

Commit

Permalink
Merge pull request #20 from smallsaucepan/cjs-flavour
Browse files Browse the repository at this point in the history
Changed build to generate CJS flavour Javascript as well as ESM
  • Loading branch information
luizbarboza authored Dec 14, 2024
2 parents da7480b + 7029ae0 commit 4471042
Show file tree
Hide file tree
Showing 4 changed files with 2,339 additions and 297 deletions.
27 changes: 21 additions & 6 deletions bench/bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

import fs from "fs"
import Benchmark from "benchmark"
import jstsUnion from "@turf/union"
import UnionOp from "jsts/org/locationtech/jts/operation/union/UnionOp.js"
import GeoJSONReader from "jsts/org/locationtech/jts/io/GeoJSONReader.js"
import w8r from "martinez-polygon-clipping"
import polyclip from "polyclip-ts"
import * as polyclip from "polyclip-ts"

const options = {
onStart() {
Expand All @@ -21,6 +22,9 @@ const options = {
},
}

// JSTS reader to reuse.
const reader = new GeoJSONReader()

const holeHole = JSON.parse(fs.readFileSync("./bench/fixtures/hole_hole.geojson"))
new Benchmark.Suite("Hole_Hole", options)
.add("polyclip-ts", () => {
Expand All @@ -36,7 +40,10 @@ new Benchmark.Suite("Hole_Hole", options)
)
})
.add("JSTS", () => {
jstsUnion(holeHole.features[0], holeHole.features[1])
UnionOp.union(
reader.read(holeHole.features[0].geometry),
reader.read(holeHole.features[1].geometry),
);
})
.run()

Expand All @@ -55,10 +62,15 @@ new Benchmark.Suite("Asia union", options)
unionPoly.geometry.coordinates,
)
})
.add("JSTS", () => jstsUnion(asia.features[0], unionPoly))
.add("JSTS", () => {
UnionOp.union(
reader.read(asia.features[0].geometry),
reader.read(unionPoly.geometry),
)
})
.run()

const states = JSON.parse(fs.readFileSync("./bench/fixtures/states_source.geojson"))
const states = JSON.parse(fs.readFileSync("./bench/fixtures/states_source.geojson"));
new Benchmark.Suite("States clip", options)
.add("polyclip-ts", () => {
polyclip.union(
Expand All @@ -73,6 +85,9 @@ new Benchmark.Suite("States clip", options)
)
})
.add("JSTS", () => {
jstsUnion(states.features[0], states.features[1])
UnionOp.union(
reader.read(states.features[0].geometry),
reader.read(states.features[1].geometry),
)
})
.run()
Loading

0 comments on commit 4471042

Please sign in to comment.