This repository has been archived by the owner on Jun 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
/
render.js
76 lines (58 loc) · 3.54 KB
/
render.js
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
'use strict'
var domino = require('domino')
var simulacra = require('../lib')
var render = require('../lib/render')
var cases = [ renderString, renderSimulacra, renderDOM, renderSimulacraDOM ]
var iterations = 1000
var sharedBinding = {
items: [ 'input', function (node, value) { node.value = value.name } ]
}
console.log('number of iterations: ' + iterations)
cases.map(function (testCase) {
var t0, result, i
// Do one warm-up iteration.
testCase()
t0 = Date.now()
for (i = 0; i < iterations; i++) testCase()
result = Date.now() - t0
console.log('test case "' + testCase.name + '" took: ' + result +
' ms (avg: ' + (result / iterations) + ' ms)')
return result
})
function renderString () {
var items = makeData().items
var result = ''
var i, j
for (i = 0, j = items.length; i < j; i++)
result += '<input value="' + items[i].name + '">'
return result
}
function renderDOM () {
var window = domino.createWindow()
var document = window.document
var body = document.body
var items = makeData().items
var i, j, element
for (i = 0, j = items.length; i < j; i++) {
element = document.createElement('input')
element.value = items[i].name
body.appendChild(element)
}
return body.innerHTML
}
function renderSimulacraDOM () {
var window = domino.createWindow('<input>')
var state = makeData()
var binding = [ 'body', {
items: [ 'input', function (node, value) { return value.name } ]
} ]
return simulacra.call(window, state, binding).innerHTML
}
function renderSimulacra () {
return render(makeData(), sharedBinding, '<input>')
}
function makeData () {
return {
items: [ {name: "a"}, {name: "b"}, {name: "c"}, {name: "a"}, {name: "b"}, {name: "c"}, {name: "a"}, {name: "b"}, {name: "c"}, {name: "a"}, {name: "b"}, {name: "c"}, {name: "a"}, {name: "b"}, {name: "c"}, {name: "a"}, {name: "b"}, {name: "c"}, {name: "a"}, {name: "b"}, {name: "c"}, {name: "a"}, {name: "b"}, {name: "c"}, {name: "a"}, {name: "b"}, {name: "c"}, {name: "a"}, {name: "b"}, {name: "c"}, {name: "a"}, {name: "b"}, {name: "c"}, {name: "a"}, {name: "b"}, {name: "c"}, {name: "a"}, {name: "b"}, {name: "c"}, {name: "a"}, {name: "b"}, {name: "c"}, {name: "a"}, {name: "b"}, {name: "c"}, {name: "a"}, {name: "b"}, {name: "c"}, {name: "a"}, {name: "b"}, {name: "c"}, {name: "a"}, {name: "b"}, {name: "c"}, {name: "a"}, {name: "b"}, {name: "c"}, {name: "a"}, {name: "b"}, {name: "c"}, {name: "a"}, {name: "b"}, {name: "c"}, {name: "a"}, {name: "b"}, {name: "c"}, {name: "a"}, {name: "b"}, {name: "c"}, {name: "a"}, {name: "b"}, {name: "c"}, {name: "a"}, {name: "b"}, {name: "c"}, {name: "a"}, {name: "b"}, {name: "c"}, {name: "a"}, {name: "b"}, {name: "c"}, {name: "a"}, {name: "b"}, {name: "c"}, {name: "a"}, {name: "b"}, {name: "c"}, {name: "a"}, {name: "b"}, {name: "c"}, {name: "a"}, {name: "b"}, {name: "c"}, {name: "a"}, {name: "b"}, {name: "c"}, {name: "a"}, {name: "b"}, {name: "c"}, {name: "a"}, {name: "b"}, {name: "c"}, {name: "a"}, {name: "b"}, {name: "c"}, {name: "a"}, {name: "b"}, {name: "c"}, {name: "a"}, {name: "b"}, {name: "c"}, {name: "a"}, {name: "b"}, {name: "c"}, {name: "a"}, {name: "b"}, {name: "c"}, {name: "a"}, {name: "b"}, {name: "c"}, {name: "a"}, {name: "b"}, {name: "c"}, {name: "a"}, {name: "b"}, {name: "c"}, {name: "a"}, {name: "b"}, {name: "c"}, {name: "a"}, {name: "b"}, {name: "c"}, {name: "a"}, {name: "b"}, {name: "c"}, {name: "a"}, {name: "b"}, {name: "c"}, {name: "a"}, {name: "b"}, {name: "c"}, {name: "a"}, {name: "b"}, {name: "c"}, {name: "a"}, {name: "b"}, {name: "c"}, {name: "a"}, {name: "b"}, {name: "c"} ]
}
}