Skip to content

Commit a9864e2

Browse files
committed
test(): caching
1 parent a19e9a6 commit a9864e2

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

test/intersect.spec.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,29 @@ describe('path-intersection', function() {
2121
expect(intersections).to.have.length(1);
2222
});
2323

24+
it('should cache paths to boost performance', function() {
25+
26+
const p1 = [
27+
[ 'M', 0, 0 ],
28+
...new Array(100).fill(0).map((_, i) => [ 'L', 100 * (i + 1), 100 * (i + 1) ])
29+
];
30+
const p2 = [
31+
[ 'M', 0, 100 * 100 ],
32+
...new Array(100).fill(0).map((_, i) => [ 'L', 100 * (i + 1), 100 * (100 - i + 1) ])
33+
].flat().join(',');
34+
35+
// when
36+
performance.mark('a')
37+
const ra = intersect(p1, p2);
38+
const { duration: a } = performance.measure('not cached', 'a');
39+
performance.mark('b')
40+
const rb = intersect(p1, p2);
41+
const { duration: b } = performance.measure('cached', 'b');
42+
// then
43+
expect(b).to.lessThanOrEqual(a);
44+
expect(rb).to.deep.eq(ra);
45+
});
46+
2447
it('parsePathCurve', function() {
2548

2649
// when

0 commit comments

Comments
 (0)