-
Notifications
You must be signed in to change notification settings - Fork 937
/
bench.ts
66 lines (62 loc) · 2.17 KB
/
bench.ts
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
59
60
61
62
63
64
65
66
import Benchmark from "benchmark";
import { featureCollection, point } from "@turf/helpers";
import {
getCluster,
clusterEach,
clusterReduce,
propertiesContainsFilter,
filterProperties,
applyFilter,
createBins,
} from "./index.js";
const geojson = featureCollection([
point([0, 0], { cluster: 0 }),
point([2, 4], { cluster: 1 }),
point([3, 6], { cluster: 1 }),
point([5, 1], { 0: "foo" }),
point([4, 2], { bar: "foo" }),
point([2, 4], {}),
point([4, 3], undefined),
]);
/**
* Benchmark Results
*
* testing -- createBins x 1,909,730 ops/sec ±2.70% (83 runs sampled)
* testing -- propertiesContainsFilter x 10,378,738 ops/sec ±2.63% (86 runs sampled)
* testing -- filterProperties x 26,212,665 ops/sec ±2.49% (85 runs sampled)
* testing -- applyFilter x 21,368,185 ops/sec ±2.71% (84 runs sampled)
* getCluster -- string filter x 3,051,513 ops/sec ±1.83% (84 runs sampled)
* getCluster -- object filter x 673,824 ops/sec ±2.20% (86 runs sampled)
* getCluster -- aray filter x 2,284,972 ops/sec ±1.90% (86 runs sampled)
* clusterEach x 890,683 ops/sec ±1.48% (87 runs sampled)
* clusterReduce x 837,383 ops/sec ±1.93% (87 runs sampled)
*/
const suite = new Benchmark.Suite("turf-clusters");
// Testing Purposes
suite
.add("testing -- createBins", () => createBins(geojson, "cluster"))
.add("testing -- propertiesContainsFilter", () =>
propertiesContainsFilter({ foo: "bar", cluster: 0 }, { cluster: 0 })
)
.add("testing -- filterProperties", () =>
filterProperties({ foo: "bar", cluster: 0 }, ["cluster"])
)
.add("testing -- applyFilter", () =>
applyFilter({ foo: "bar", cluster: 0 }, ["cluster"])
);
suite
.add("getCluster -- string filter", () => getCluster(geojson, "cluster"))
.add("getCluster -- object filter", () => getCluster(geojson, { cluster: 1 }))
.add("getCluster -- aray filter", () => getCluster(geojson, ["cluster"]))
.add("clusterEach", () =>
clusterEach(geojson, "cluster", (cluster) => {
return cluster;
})
)
.add("clusterReduce", () =>
clusterReduce(geojson, "cluster", (previousValue, cluster) => {
return cluster;
})
)
.on("cycle", (e) => console.log(String(e.target)))
.run();