-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathjs-framework-benchmark.html
155 lines (136 loc) · 4.7 KB
/
js-framework-benchmark.html
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>sprae</title>
<link href="./css/bootstrap.min.css" rel="stylesheet">
<link href="./css/main.css" rel="stylesheet">
</head>
<body>
<div id="main">
<div class="container">
<div class="jumbotron">
<div class="row">
<div class="col-md-6">
<h1>sprae</h1>
</div>
<div class="col-md-6">
<div class="row">
<div class="col-sm-6 smallpad">
<button :onclick="e => run()" type="button" class="btn btn-primary btn-block" id="run">Create 1,000
rows</button>
</div>
<div class="col-sm-6 smallpad">
<button :onclick="e => runLots()" type="button" class="btn btn-primary btn-block" id="runlots">Create
10,000
rows</button>
</div>
<div class="col-sm-6 smallpad">
<button :onclick="e => add()" type="button" class="btn btn-primary btn-block" id="add">Append 1,000
rows</button>
</div>
<div class="col-sm-6 smallpad">
<button :onclick="e => update()" type="button" class="btn btn-primary btn-block" id="update">Update
every 10th
row</button>
</div>
<div class="col-sm-6 smallpad">
<button :onclick="e => clear()" type="button" class="btn btn-primary btn-block"
id="clear">Clear</button>
</div>
<div class="col-sm-6 smallpad">
<button :onclick="e => swap()" type="button" class="btn btn-primary btn-block" id="swaprows">Swap
Rows</button>
</div>
</div>
</div>
</div>
</div>
<table class="table table-hover table-striped test-data">
<tr :each="item in rows" :class="{danger: selected && item.id == selected.id}">
<td class="col-md-1" :text="item.id"></td>
<td class="col-md-4">
<a role="select" :onclick="e => select(item)" :text="item.label"></a>
</td>
<td class="col-md-1">
<a>
<span role="delete" :onclick="e => remove(item)" class="glyphicon glyphicon-remove"
aria-hidden="true"></span>
</a>
</td>
<td class="col-md-6"></td>
</tr>
</table>
</div>
<span class="preloadicon glyphicon glyphicon-remove" aria-hidden="true"></span>
</div>
<script type="importmap">
{
"imports": {
"ulive": "../node_modules/ulive/dist/ulive.es.js"
}
}
</script>
<script type="module">
import sprae from '../sprae.js'
const adjectives = ['pretty', 'large', 'big', 'small', 'tall', 'short', 'long', 'handsome', 'plain', 'quaint', 'clean', 'elegant', 'easy', 'angry', 'crazy', 'helpful', 'mushy', 'odd', 'unsightly', 'adorable', 'important', 'inexpensive', 'cheap', 'expensive', 'fancy']
const colours = ['red', 'yellow', 'blue', 'green', 'pink', 'brown', 'purple', 'brown', 'white', 'black', 'orange']
const nouns = ['table', 'chair', 'house', 'bbq', 'desk', 'car', 'pony', 'cookie', 'sandwich', 'burger', 'pizza', 'mouse', 'keyboard']
let nextId = 1
function buildData(count) {
const data = []
for (let i = 0; i < count; i++) {
data.push({
id: nextId++,
label: `${adjectives[_random(adjectives.length)]} ${colours[_random(colours.length)]} ${nouns[_random(nouns.length)]}`,
})
}
return data
}
function _random(max) {
return Math.round(Math.random() * 1000) % max
}
sprae(document.getElementById('main'), {
rows: buildData(3),
selected: null,
remove(item) {
const index = this.rows.findIndex(x => (x.id == item.id))
this.rows.splice(index, 1)
},
select(item) {
console.time('select', item)
this.selected = item
console.timeEnd('select')
},
run() {
this.rows = buildData(1000)
this.selected = null
},
add() {
this.rows = [...this.rows, ...buildData(1000)]
this.selected = null
},
update() {
for (let i = 0; i < this.rows.length; i += 10) {
this.rows[i].label += ' !!!'
}
this.selected = null
},
runLots() {
this.rows = buildData(10000)
this.selected = null
},
clear() {
this.rows = []
this.selected = null
},
swap() {
if (this.rows.length > 998) {
let rows = this.rows;
[rows[1], rows[998]] = [rows[998], rows[1]]
}
}
})
</script>
</body>
</html>