summaryrefslogtreecommitdiffstats
path: root/bench/tests/10000-accesses.js
blob: ed149e158e411a733333fd3798d2d3daa207f7a8 (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
SVG.bench.describe(
  'Access a dom attributes vs dom properties vs object properties',
  function (bench) {
    bench.test('using an object', function () {
      var sum = 0
      var obj = { x: '30' }
      for (var i = 0; i < 1000000; i++) {
        sum += obj.x * i
      }
      console.log(sum)
    })

    bench.test('figure out what the overhead is', function () {
      var obj = bench.draw.rect(100, 100).move(0, 0)
    })

    bench.test('using dom attributes', function () {
      var sum = 0
      var obj = bench.draw.rect(100, 100).move(0, 0)
      var node = obj.node
      for (var i = 0; i < 1000000; i++) {
        sum += node.getAttribute('x') * i
      }
      console.log(sum, node.getAttribute('x'))
    })

    bench.test('using dom properties', function () {
      var sum = 0
      var obj = bench.draw.rect(100, 100).move(0, 0)
      var node = obj.node
      for (var i = 0; i < 1000000; i++) {
        sum += node.x.baseVal * i
      }
      console.log(sum, node.x)
    })
  }
)