'use strict'

const self = (global || root)

self.performance = {
  now: function () {
    var hrtime = process.hrtime()
    return ((hrtime[0] * 1000000 + hrtime[1] / 1000) / 1000)
  }
}

function generateGrid (rowCount, columnCount) {
  var grid = []

  for (var r = 0; r < rowCount; r++) {
    var row = { id: r, items: [] }
    for (var c = 0; c < columnCount; c++) {
      row.items.push({ id: (r + '-' + c) })
    }
    grid.push(row)
  }

  return grid
}

const gridData = generateGrid(1000, 10)

const five = [0, 1, 2, 3, 4]

module.exports = {
  template: '<div><h1>{{ Math.random() }}</h1><my-table></my-table></div>',
  components: {
    myTable: {
      data: function () {
        return {
          grid: gridData
        }
      },
      // template: '<table><tr v-for="row in grid"><th>123</th><td v-for="item in row.items">{{ item.id }}</td></tr></table>',
      template: '<table width="100%" cellspacing="2"><row v-for="row in grid" :row="row"></row></table>',
      components: {
        row: {
          props: ['row'],
          // template: '<tr><th>{{ Math.random() }}</th><column v-for="item in row.items"></column></tr>',
          render (h) {
            return h('tr', [
              new TextNode(1, [
                new TextNode(2),
                ...this.row.items.map(item => h('column'))
              ])
            ])
          },
          components: {
            column: {
              render (h) {
                return h('td', { class: 'item' }, [
                  new TextNode(4,
                    five.map(() => new TextNode(5,
                      five.map(() => new TextNode(6, [new TextNode(7)])))
                    )
                  )
                ])
              }
              // template: '<td class="item">' +
              //   // 25 plain elements for each cell
              //   '<ul class="yoyo">' +
              //     '<li class="hihi" v-for="i in 5">' +
              //       '<span v-for="i in 5">fsefs</span>' +
              //       '</li>' +
              //   '</ul>' +
              // '</td>'
            }
          }
        }
      }
    }
  }
}

const renderFns = [
  { open: () => `<tr>`, close: `</tr>` },
  { open: () => `<th>`, close: `</th>` },
  { open: () => Math.random() },
  { open: () => `<td class="item">`, close: `</td>` },
  { open: () => `<ul class="yoyo">`, close: `</ul>` },
  { open: () => `<li class="hihi">`, close: `</li>` },
  { open: () => `<span>`, close: `</span>` },
  { open: () => `fsefs` }
]

function TextNode (id, children) {
  this.isTextNode = true
  this.open = renderFns[id].open
  this.close = renderFns[id].close
  this.children = children
}

@@ -501,38 +501,8 @@
 0)%0A%0A
-const five = %5B0, 1, 2, 3, 4%5D%0A%0A
 modu
@@ -1005,35 +1005,32 @@
 row'%5D,%0A         
- //
  template: '%3Ctr%3E
@@ -1122,596 +1122,57 @@
     
-render (h) %7B%0A            return h('tr', %5B%0A              new TextNode(1, %5B%0A                new TextNode(2),%0A                ...this.row.items.map(item =%3E h('column'))%0A              %5D)%0A            %5D)%0A          %7D,%0A          components: %7B%0A            column: %7B%0A              render (h) %7B%0A                return h('td', %7B class: 'item' %7D, %5B%0A                  new TextNode(4,%0A                    five.map(() =%3E new TextNode(5,%0A                      five.map(() =%3E new TextNode(6, %5Bnew TextNode(7)%5D)))%0A                    )%0A                  )%0A                %5D)%0A              %7D%0A              //
+components: %7B%0A            column: %7B%0A             
  tem
@@ -1213,19 +1213,16 @@
         
- //
    // 25
@@ -1260,27 +1260,24 @@
             
- //
    '%3Cul clas
@@ -1298,27 +1298,24 @@
             
- //
      '%3Cli cl
@@ -1349,35 +1349,32 @@
  +%0A             
- //
        '%3Cspan v-
@@ -1415,19 +1415,16 @@
         
- //
        '
@@ -1445,19 +1445,16 @@
         
- //
    '%3C/ul
@@ -1471,19 +1471,16 @@
         
- //
  '%3C/td%3E'
@@ -1540,539 +1540,4 @@
 %7D%0A%7D%0A
-%0Aconst renderFns = %5B%0A  %7B open: () =%3E %60%3Ctr%3E%60, close: %60%3C/tr%3E%60 %7D,%0A  %7B open: () =%3E %60%3Cth%3E%60, close: %60%3C/th%3E%60 %7D,%0A  %7B open: () =%3E Math.random() %7D,%0A  %7B open: () =%3E %60%3Ctd class=%22item%22%3E%60, close: %60%3C/td%3E%60 %7D,%0A  %7B open: () =%3E %60%3Cul class=%22yoyo%22%3E%60, close: %60%3C/ul%3E%60 %7D,%0A  %7B open: () =%3E %60%3Cli class=%22hihi%22%3E%60, close: %60%3C/li%3E%60 %7D,%0A  %7B open: () =%3E %60%3Cspan%3E%60, close: %60%3C/span%3E%60 %7D,%0A  %7B open: () =%3E %60fsefs%60 %7D%0A%5D%0A%0Afunction TextNode (id, children) %7B%0A  this.isTextNode = true%0A  this.open = renderFns%5Bid%5D.open%0A  this.close = renderFns%5Bid%5D.close%0A  this.children = children%0A%7D%0A

revert to original bench code