Skip to content

Commit ef16424

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

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

test/intersect.spec.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,30 @@ 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 max = 1000;
27+
const p1 = [
28+
[ 'M', 0, 0 ],
29+
...new Array(max).fill(0).map((_, i) => [ 'L', max * (i + 1), max * (i + 1) ])
30+
];
31+
const p2 = [
32+
[ 'M', 0, max * max ],
33+
...new Array(max).fill(0).map((_, i) => [ 'L', max * (i + 1), max * (max - i + 1) ])
34+
].flat().join(',');
35+
36+
// when
37+
performance.mark('a')
38+
const ra = intersect(p1, p2);
39+
const { duration: a } = performance.measure('not cached', 'a');
40+
performance.mark('b')
41+
const rb = intersect(p1, p2);
42+
const { duration: b } = performance.measure('cached', 'b');
43+
// then
44+
expect(b).to.lessThanOrEqual(a);
45+
expect(rb).to.deep.eq(ra);
46+
});
47+
2448
it('parsePathCurve', function() {
2549

2650
// when

0 commit comments

Comments
 (0)