Skip to content

Commit b15141a

Browse files
author
0x8890
committed
add simulacra-v1.5.5
1 parent 309e3d7 commit b15141a

File tree

4 files changed

+239
-0
lines changed

4 files changed

+239
-0
lines changed

index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ <h3 class="panel-title">Choose a framework:</h3>
4343
<li><a href="react-v15.3.1-mobX-v2.5.0/index.html"><span class="glyphicon glyphicon-arrow-right" aria-hidden="true"></span> React v15.3.1 MobX v2.5.0</a></li>
4444
<li><a href="react-v15.3.2-redux-v3.6.0/index.html"><span class="glyphicon glyphicon-arrow-right" aria-hidden="true"></span> React v15.3.2 Redux v3.6.0</a></li>
4545
<li><a href="riot-v2.6.1/index.html"><span class="glyphicon glyphicon-arrow-right" aria-hidden="true"></span> riot-v2.6.1</a></li>
46+
<li><a href="simulacra-v1.5.5/index.html"><span class="glyphicon glyphicon-arrow-right" aria-hidden="true"></span> Simulacra.js v1.5.5</a></li>
4647
<li><a href="tsers-v1.0.0/index.html"><span class="glyphicon glyphicon-arrow-right" aria-hidden="true"></span> TSERS v1.0.0</a></li>
4748
<li><a href="vanillajs/index.html"><span class="glyphicon glyphicon-arrow-right" aria-hidden="true"></span> VanillaJS</a></li>
4849
<li><a href="vidom-v0.3.18/index.html"><span class="glyphicon glyphicon-arrow-right" aria-hidden="true"></span> Vidom v0.3.18</a></li>

simulacra-v1.5.5/index.html

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Simulacra.js v1.5.5</title>
6+
<link href="../css/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet"/>
7+
<link href="../css/main.css" rel="stylesheet"/>
8+
</head>
9+
<body>
10+
<template id="main">
11+
<div class="container">
12+
<div class="jumbotron">
13+
<div class="row">
14+
<div class="col-md-6">
15+
<h1>Simulacra.js v1.5.5</h1>
16+
</div>
17+
<div class="col-md-6">
18+
<div class="row">
19+
<div class="col-sm-6 smallpad">
20+
<button type="button" class="btn btn-primary btn-block" id="run">Create 1,000 rows</button>
21+
</div>
22+
<div class="col-sm-6 smallpad">
23+
<button type="button" class="btn btn-primary btn-block" id="runlots">Create 10,000 rows</button>
24+
</div>
25+
<div class="col-sm-6 smallpad">
26+
<button type="button" class="btn btn-primary btn-block" id="add">Append 1,000 rows</button>
27+
</div>
28+
<div class="col-sm-6 smallpad">
29+
<button type="button" class="btn btn-primary btn-block" id="update">Update every 10th row</button>
30+
</div>
31+
<div class="col-sm-6 smallpad">
32+
<button type="button" class="btn btn-primary btn-block" id="clear">Clear</button>
33+
</div>
34+
<div class="col-sm-6 smallpad">
35+
<button type="button" class="btn btn-primary btn-block" id="swaprows">Swap Rows</button>
36+
</div>
37+
</div>
38+
</div>
39+
</div>
40+
</div>
41+
<table class="table table-hover table-striped test-data">
42+
<tbody>
43+
<tr>
44+
<td class="col-md-1"></td>
45+
<td class="col-md-4">
46+
<a></a>
47+
</td>
48+
<td class="col-md-1">
49+
<a><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></a>
50+
</td>
51+
<td class="col-md-6"></td>
52+
</tr>
53+
</tbody>
54+
</table>
55+
</div>
56+
</template>
57+
<script src="dist/main.js"></script>
58+
</body>
59+
</html>

simulacra-v1.5.5/package.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "js-framework-benchmark-simulacra",
3+
"version": "1.0.0",
4+
"description": "Benchmark for simulacra.js",
5+
"scripts": {
6+
"build-dev": "browserify src/main.js -o dist/main.js",
7+
"build-prod": "browserify src/main.js -o dist/main.js"
8+
},
9+
"keywords": [
10+
"simulacra"
11+
],
12+
"author": "Stefan Krause",
13+
"license": "Apache-2.0",
14+
"homepage": "https://github.com/krausest/js-framework-benchmark",
15+
"repository": {
16+
"type": "git",
17+
"url": "https://github.com/krausest/js-framework-benchmark.git"
18+
},
19+
"devDependencies": {
20+
"browserify": "^13.1.1"
21+
},
22+
"dependencies": {
23+
"simulacra": "^1.5.5"
24+
}
25+
}

simulacra-v1.5.5/src/main.js

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
'use strict'
2+
3+
var bindObject = require('simulacra')
4+
var flow = bindObject.flow
5+
var setDefault = bindObject.setDefault
6+
var bindEvents = bindObject.bindEvents
7+
8+
var state = { rows: [] }
9+
10+
var binding = [ '#main', {
11+
rows: [ 'tr', {
12+
id: 'td:nth-of-type(1)',
13+
label: [ 'td:nth-of-type(2) a', flow(
14+
setDefault,
15+
bindEvents({
16+
click: function (event, path) {
17+
bench('select', function () {
18+
var i = 0, j = path.root.rows.length
19+
20+
for (; i < j; i++)
21+
if (path.root.rows[i].isSelected)
22+
path.root.rows[i].isSelected = false
23+
24+
path.target.isSelected = true
25+
})
26+
}
27+
})
28+
) ],
29+
isSelected: function (node, value) {
30+
node.className = value ? 'danger' : ''
31+
}
32+
}, bindEvents({
33+
click: function (event, path) {
34+
if (event.target.tagName === 'SPAN') {
35+
bench('delete', function () {
36+
var id = event.target.parentNode.parentNode
37+
.parentNode.childNodes[1].textContent
38+
39+
path.target.rows.splice(path.target.rows.findIndex(function (obj) {
40+
return obj.id === id
41+
}), 1)
42+
})
43+
}
44+
}
45+
}) ]
46+
} ]
47+
48+
var methods = {
49+
run: create('run', 1000),
50+
add: function () {
51+
bench('add', function () {
52+
state.rows.push.apply(state.rows, buildData(1000))
53+
})
54+
},
55+
runlots: create('runLots', 10000),
56+
update: function () {
57+
bench('update', function () {
58+
var i
59+
60+
for (i = 0; i < state.rows.length; i++)
61+
if (i % 10 === 0) state.rows[i].label += ' !!!'
62+
})
63+
},
64+
swaprows: function () {
65+
bench('swapRows', function () {
66+
var a, b
67+
68+
if (state.rows.length > 10) {
69+
a = Object.assign({}, state.rows[4])
70+
b = Object.assign({}, state.rows[9])
71+
Object.assign(state.rows[4], b)
72+
Object.assign(state.rows[9], a)
73+
}
74+
})
75+
},
76+
clear: function () {
77+
bench('clear', function () {
78+
state.rows = []
79+
})
80+
}
81+
}
82+
83+
document.body.appendChild(bindObject(state, binding))
84+
document.body.addEventListener('click', function (event) {
85+
var id = event.target.id
86+
if (id) methods[id]()
87+
})
88+
89+
var adjectives = [
90+
"pretty", "large", "big", "small", "tall", "short", "long", "handsome",
91+
"plain", "quaint", "clean", "elegant", "easy", "angry", "crazy", "helpful",
92+
"mushy", "odd", "unsightly", "adorable", "important", "inexpensive", "cheap",
93+
"expensive", "fancy"
94+
]
95+
96+
var colours = [
97+
"red", "yellow", "blue", "green", "pink", "brown", "purple", "brown",
98+
"white", "black", "orange"
99+
]
100+
101+
var nouns = [
102+
"table", "chair", "house", "bbq", "desk", "car", "pony", "cookie",
103+
"sandwich", "burger", "pizza", "mouse", "keyboard"
104+
]
105+
106+
var id = 0
107+
108+
function create (label, number) {
109+
return function () {
110+
bench(label, function () {
111+
var i = 0, data = buildData(number)
112+
113+
for (; i < number; i++) {
114+
if (i < state.rows.length - 1) {
115+
state.rows[i].id = data[i].id
116+
state.rows[i].label = data[i].label
117+
}
118+
else state.rows.push(data[i])
119+
}
120+
121+
state.rows.splice(number, state.rows.length - number)
122+
})
123+
}
124+
}
125+
126+
function random (max) {
127+
return Math.round(Math.random() * 1000) % max
128+
}
129+
130+
function buildData (count) {
131+
var data = [], i
132+
133+
for (i = 0; i < count; i++) {
134+
id++
135+
data.push({
136+
id: '' + id,
137+
label:
138+
adjectives[random(adjectives.length)] + " " +
139+
colours[random(colours.length)] + " " +
140+
nouns[random(nouns.length)]
141+
})
142+
}
143+
144+
return data
145+
}
146+
147+
function bench (label, fn) {
148+
var t0 = performance.now(), t1
149+
fn()
150+
requestAnimationFrame(function () {
151+
t1 = performance.now()
152+
console.log(label + ' took ' + (t1 - t0))
153+
})
154+
}

0 commit comments

Comments
 (0)