-
-
Notifications
You must be signed in to change notification settings - Fork 77
/
bench.js
58 lines (52 loc) · 1.74 KB
/
bench.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import load from 'load-json-file';
import Benchmark from 'benchmark';
import jstsUnion from '@turf/union';
import martinez from './dist/martinez.umd';
/**
* Benmark Results
*
* Hole_Hole x 13,345 ops/sec ±2.13% (91 runs sampled)
* Hole_Hole - JSTS x 1,724 ops/sec ±4.80% (87 runs sampled)
* Asia x 6.32 ops/sec ±3.16% (20 runs sampled)
* Asia - JSTS x 6.62 ops/sec ±2.74% (21 runs sampled)
*/
const options = {
onStart (event) { console.log(this.name); },
onError (event) { console.log(event.target.error); },
onCycle (event) { console.log(String(event.target)); },
onComplete() {
console.log('- Fastest is ' + this.filter('fastest').map('name') + '\n');
}
};
const hole_hole = load.sync('./test/fixtures/hole_hole.geojson');
new Benchmark.Suite('Hole_Hole', options)
.add('Martinez', () => {
martinez.union(
hole_hole.features[0].geometry.coordinates,
hole_hole.features[1].geometry.coordinates);
})
.add('JSTS', () => {
jstsUnion(hole_hole.features[0], hole_hole.features[1]);
})
.run();
const asia = load.sync('./test/fixtures/asia.geojson');
const unionPoly = load.sync('./test/fixtures/asia_unionPoly.geojson');
new Benchmark.Suite('Asia union', options)
.add('Martinez', () => {
martinez.union(
asia.features[0].geometry.coordinates,
unionPoly.geometry.coordinates);
})
.add('JSTS', () => jstsUnion(asia.features[0], unionPoly))
.run();
const states = load.sync('./test/fixtures/states_source.geojson');
new Benchmark.Suite('States clip', options)
.add('Martinez', () => {
martinez.union(
states.features[0].geometry.coordinates,
states.features[1].geometry.coordinates);
})
.add('JSTS', () => {
jstsUnion(states.features[0], states.features[1]);
})
.run();