Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernize 2024 #171

Merged
merged 6 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
7 changes: 2 additions & 5 deletions .github/workflows/node.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@ jobs:
- name: Install dependencies
run: npm ci

- name: Build the dev bundle
run: npm run build-dev

- name: Build the min bundle
run: npm run build-min
- name: Build the bundle
run: npm run build

- name: Run tests
run: npm test
19 changes: 12 additions & 7 deletions bench/basic.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
const earcut = require('../src/earcut');
import {earcut, flatten} from '../src/earcut.js';
import {readFileSync} from 'fs';

const {vertices, holes} = earcut.flatten(require('../test/fixtures/water.json'));
const data = JSON.parse(readFileSync(new URL('../test/fixtures/building.json', import.meta.url)));
const {vertices, holes} = flatten(data);

let start = Date.now(),
ops = 0;
const start = performance.now();
let ops = 0;
let passed = 0;

while (Date.now() - start < 1000) {
do {
earcut(vertices, holes);

ops++;
}
passed = performance.now() - start;
} while (passed < 1000);

console.log(Math.round(ops * 1000 / (Date.now() - start)) + ' ops/s');
console.log(`${Math.round(ops * 1000 / passed).toLocaleString()} ops/s`);
20 changes: 12 additions & 8 deletions bench/bench.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const earcut = require('../src/earcut');
import {earcut, flatten} from '../src/earcut.js';
import Benchmark from 'benchmark';
import {readFileSync} from 'fs';

function withoutHoles({vertices, holes, dimensions}) {
return {
Expand All @@ -7,19 +9,21 @@ function withoutHoles({vertices, holes, dimensions}) {
};
}

function getFixture(name) {
return flatten(JSON.parse(readFileSync(new URL(`../test/fixtures/${name}`, import.meta.url))));
}

const samples = {
'typical OSM building': earcut.flatten(require('../test/fixtures/building.json')),
'dude shape': withoutHoles(earcut.flatten(require('../test/fixtures/dude.json'))),
'dude shape with holes': earcut.flatten(require('../test/fixtures/dude.json')),
'complex OSM water': earcut.flatten(require('../test/fixtures/water.json'))
'typical OSM building': getFixture('building.json'),
'dude shape': withoutHoles(getFixture('dude.json')),
'dude shape with holes': getFixture('dude.json'),
'complex OSM water': getFixture('water.json')
};

const Benchmark = require('benchmark');

for (const name in samples) {
const {vertices, holes, dimensions} = samples[name];
new Benchmark.Suite()
.add(name + ' (' + (vertices.length / 2) + ' vertices):', function () {
.add(`${name} (${vertices.length / 2} vertices):`, () => {
earcut(vertices, holes, dimensions);
})
.on('cycle', logCycle)
Expand Down
1 change: 1 addition & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {default} from 'eslint-config-mourner';
Loading
Loading