point-in-polygon-hao icon indicating copy to clipboard operation
point-in-polygon-hao copied to clipboard

Improve performance and reduce size

Open zaygraveyard opened this issue 1 year ago • 0 comments

Increase performance ~30% in the first benchmark but decrease it by less than 10% in the second.

By reordering and merging the conditions. Also reduce the minified file size by ~25% (from 870B to ~~666B~~ 663B).

Before

point-in-poly-hao x 57,119,969 ops/sec ±0.42% (96 runs sampled)
turf-point-in-polygon x 22,445,351 ops/sec ±0.59% (98 runs sampled)
point-in-polygon x 56,122,754 ops/sec ±0.49% (101 runs sampled)
robust-point-in-polygon x 45,084,666 ops/sec ±0.12% (97 runs sampled)
Fastest is point-in-poly-hao

point-in-poly-hao x 788,736 ops/sec ±0.13% (100 runs sampled)
turf-point-in-polygon x 393,184 ops/sec ±0.08% (102 runs sampled)
point-in-polygon x 447,820 ops/sec ±0.16% (100 runs sampled)
robust-point-in-polygon x 537,364 ops/sec ±0.14% (98 runs sampled)
Fastest is point-in-poly-hao

After

point-in-poly-hao x 72,107,218 ops/sec ±0.44% (97 runs sampled)
turf-point-in-polygon x 22,556,234 ops/sec ±0.22% (97 runs sampled)
point-in-polygon x 56,929,933 ops/sec ±0.39% (93 runs sampled)
robust-point-in-polygon x 45,678,082 ops/sec ±0.27% (99 runs sampled)
Fastest is point-in-poly-hao

point-in-poly-hao x 731,341 ops/sec ±0.40% (101 runs sampled)
turf-point-in-polygon x 397,664 ops/sec ±0.11% (101 runs sampled)
point-in-polygon x 453,172 ops/sec ±0.14% (100 runs sampled)
robust-point-in-polygon x 547,462 ops/sec ±0.11% (99 runs sampled)
Fastest is point-in-poly-hao

Benchmarked on an Apple M1 MacBook Air 2020 with 16GB of memory, running macOS Ventura 13.3.1 and using node v20.0.0.

zaygraveyard avatar Apr 28 '23 23:04 zaygraveyard