summaryrefslogtreecommitdiffstats
path: root/bench/tests/10000-pointArray-bbox.js
blob: 8c9c42ce101daef0a9b55934b66571cdc098073b (plain)
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
SVG.bench.describe('Generate 10000 pathArrays bbox', function (bench) {
  var data =
    '209,153 389,107 547,188 482,289 374,287 91,254 407,243 391,185 166,226 71,177 65,52 234,50 107,136 163,199 158,131 323,45 218,145 305,190 374,143 174,216 296,241'

  var dataArr = [
    [209, 153],
    [389, 107],
    [547, 188],
    [482, 289],
    [374, 287],
    [91, 254],
    [407, 243],
    [391, 185],
    [166, 226],
    [71, 177],
    [65, 52],
    [234, 50],
    [107, 136],
    [163, 199],
    [158, 131],
    [323, 45],
    [218, 145],
    [305, 190],
    [374, 143],
    [174, 216],
    [296, 241]
  ]

  bench.test('using SVG.js v3.0.0', function () {
    for (var i = 0; i < 10000; i++) {
      SVG.parser.poly.setAttribute('points', data)
      SVG.parser.poly.getBBox()
    }
  })

  bench.test('using SVG.js v3.0.0 without parser', function () {
    for (var i = 0; i < 10000; i++) {
      var maxX = -Infinity,
        maxY = -Infinity,
        minX = Infinity,
        minY = Infinity
      dataArr.forEach(function (el) {
        maxX = Math.max(el[0], maxX)
        maxY = Math.max(el[1], maxY)
        minX = Math.min(el[0], minX)
        minY = Math.min(el[1], minY)
      })
      var a = { x: minX, y: minY, width: maxX - minX, height: maxY - minY }
    }
    //new SVG.Path().attr('d', data).addTo(draw).bbox()
  })
})