Skip to content

Commit 6880827

Browse files
committed
Merge branch 'master' of https://github.com/hville/js-framework-benchmark into hville-master
2 parents aeaf355 + a548ec3 commit 6880827

File tree

8 files changed

+293
-0
lines changed

8 files changed

+293
-0
lines changed

pico-dom-v0.18.0/index.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8"/>
5+
<title>picoDOM-"keyed"</title>
6+
<link href="/css/currentStyle.css" rel="stylesheet"/>
7+
</head>
8+
<body>
9+
<script src='dist/main.js'></script>
10+
</body>
11+
</html>

pico-dom-v0.18.0/package.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "js-framework-benchmark-pico-dom-0.17.0",
3+
"version": "0.1.0",
4+
"description": "Benchmark for picoDom 0.17.0",
5+
"scripts": {
6+
"build-dev": "webpack -w -d --entry ./src/main.js --output-filename ./dist/main.js",
7+
"build-prod": "webpack -p --entry ./src/main.js --output-filename ./dist/main.js"
8+
},
9+
"author": "Hugo Villeneuve",
10+
"license": "Apache-2.0",
11+
"homepage": "https://github.com/krausest/js-framework-benchmark",
12+
"repository": {
13+
"type": "git",
14+
"url": "https://github.com/krausest/js-framework-benchmark.git"
15+
},
16+
"devDependencies": {},
17+
"dependencies": {
18+
"pico-dom": "0.18.0"
19+
}
20+
}

pico-dom-v0.18.0/src/main.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*eslint indent:0 quotes:0*/
2+
var el = require('pico-dom').element,
3+
menu = require('./menu'),
4+
table = require('./table'),
5+
Store = require('./store')
6+
7+
var title = 'picoDom-keyed',
8+
store = new Store()
9+
10+
el(document.body,
11+
el('div#main',
12+
el('div.container',
13+
el('div.jumbotron',
14+
el('div.row',
15+
el('div.col-md-6',
16+
el('h1', title)
17+
),
18+
el('div.col-md-6', menu)
19+
)
20+
),
21+
table,
22+
el('span.preloadicon.glyphicon.glyphicon-remove[aria-hidden]')
23+
)
24+
)
25+
)
26+
menu.update(store)

pico-dom-v0.18.0/src/menu.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*eslint indent:0 quotes:0*/
2+
var pico = require('pico-dom'),
3+
table = require('./table'),
4+
time = require('./time')
5+
6+
var el = pico.element,
7+
co = pico.component
8+
9+
module.exports = co('div.row', {
10+
extra: {
11+
store: null,
12+
update: function(s) { this.store = s },
13+
handleEvent: handleClick,
14+
init: function() { this.node.addEventListener('click', this, true) }
15+
}
16+
}, [
17+
el('div.col-sm-6.smallpad',
18+
co('button[type=button].btn.btn-primary.btn-block#run', {extra: {key: 'run'}}, 'Create 1,000 rows')
19+
),
20+
el('div.col-sm-6.smallpad',
21+
co('button[type=button].btn.btn-primary.btn-block#runlots', {extra: {key: 'runLots'}}, 'Create 10,000 rows')
22+
),
23+
el('div.col-sm-6.smallpad',
24+
co('button[type=button].btn.btn-primary.btn-block#add', {extra: {key: 'add'}}, 'Append 1,000 rows')
25+
),
26+
el('div.col-sm-6.smallpad',
27+
co('button[type=button].btn.btn-primary.btn-block#update', {extra: {key: 'update'}}, 'Update every 10th row')
28+
),
29+
el('div.col-sm-6.smallpad',
30+
co('button[type=button].btn.btn-primary.btn-block#clear', {extra: {key: 'clear'}}, 'Clear')
31+
),
32+
el('div.col-sm-6.smallpad',
33+
co('button[type=button].btn.btn-primary.btn-block#swaprows', {extra: {key: 'swapRows'}}, 'Swap Rows')
34+
)
35+
])
36+
function handleClick(e) {
37+
var target = pico.extra.get(e.target),
38+
key = target && target.key,
39+
store = this.store
40+
if (!key) return
41+
42+
e.preventDefault()
43+
time.start(key)
44+
switch (key) {
45+
case 'run':
46+
store.clear()
47+
store.run()
48+
break
49+
case 'add':
50+
store.add()
51+
break
52+
case 'runLots':
53+
store.clear()
54+
store.runLots()
55+
break
56+
case 'update':
57+
store.update()
58+
break
59+
case 'clear':
60+
store.clear()
61+
break
62+
case 'swapRows':
63+
if (store.data.length>10) store.swapRows()
64+
}
65+
table.update(store)
66+
time.stop()
67+
}

pico-dom-v0.18.0/src/store.js

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*eslint indent:0 quotes:0*/
2+
module.exports = Store
3+
4+
function _random(max) {
5+
return Math.round(Math.random()*1000)%max
6+
}
7+
8+
function Store() {
9+
this.data = []
10+
this.backup = null
11+
this.selected = null
12+
this.id = 1
13+
}
14+
Store.prototype = {
15+
constructor: Store,
16+
buildData: function(count) {
17+
if (!(count >=0)) count = 1000
18+
var 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"]
19+
var colours = ["red", "yellow", "blue", "green", "pink", "brown", "purple", "brown", "white", "black", "orange"]
20+
var nouns = ["table", "chair", "house", "bbq", "desk", "car", "pony", "cookie", "sandwich", "burger", "pizza", "mouse", "keyboard"]
21+
var data = []
22+
for (var i=0; i < count; ++i)
23+
data.push({id: this.id++, label: adjectives[_random(adjectives.length)] + " " + colours[_random(colours.length)] + " " + nouns[_random(nouns.length)] })
24+
return data
25+
},
26+
updateData: function(mod) {
27+
if (!(mod >=0)) mod = 1000
28+
for (var i=0; i<this.data.length; i+=10) {
29+
this.data[i].label += ' !!!'
30+
}
31+
},
32+
delete: function(id) {
33+
var idx = this.data.findIndex(function(d) { return d.id == id }) //eslint-disable-line eqeqeq
34+
this.data = this.data.filter(function(e,i) { return i != idx }) //eslint-disable-line eqeqeq
35+
return this
36+
},
37+
run: function() {
38+
this.data = this.buildData()
39+
this.selected = null
40+
},
41+
add: function() {
42+
this.data = this.data.concat(this.buildData(1000))
43+
this.selected = null
44+
},
45+
update: function() {
46+
this.updateData()
47+
this.selected = null
48+
},
49+
select: function(id) {
50+
this.selected = id
51+
},
52+
hideAll: function() {
53+
this.backup = this.data
54+
this.data = []
55+
this.selected = null
56+
},
57+
showAll: function() {
58+
this.data = this.backup
59+
this.backup = null
60+
this.selected = null
61+
},
62+
runLots: function() {
63+
this.data = this.buildData(10000)
64+
this.selected = null
65+
},
66+
clear: function() {
67+
this.data = []
68+
this.selected = null
69+
},
70+
swapRows: function() {
71+
if(this.data.length > 10) {
72+
var a = this.data[4]
73+
this.data[4] = this.data[9]
74+
this.data[9] = a
75+
}
76+
}
77+
}

pico-dom-v0.18.0/src/table.js

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*eslint indent:0 quotes:0*/
2+
var pico = require('pico-dom'),
3+
time = require('./time')
4+
5+
var el = pico.element,
6+
co = pico.component,
7+
list = pico.list,
8+
extra = pico.extra
9+
10+
var store = null
11+
12+
var rows = list(co('tr', {
13+
extra: { key: -1, update: updateRow, init: function() { this.node.onclick = rowClickHandler } }
14+
}, [
15+
co('td.col-md-1', {
16+
extra: { init: function(v) { this.setText(v && v.id) } }
17+
}),
18+
co('td.col-md-4',
19+
co('a.lbl', {
20+
extra: { key: 'select', update: updateLabel }
21+
})
22+
),
23+
el('td.col-md-1',
24+
el('a.remove',
25+
co('span.glyphicon.glyphicon-remove.remove[aria-hidden]', {
26+
extra: { key: 'delete' }
27+
})
28+
)
29+
),
30+
el('td.col-md-6')
31+
]),
32+
'id'
33+
)
34+
35+
var table = module.exports = co('table.table.table-hover.table-striped.test-data',
36+
co('tbody#tbody', {
37+
extra: { update: function(str) {
38+
store = str
39+
this.update = function(s) { rows.update(s.data) } // run-once switcharoo
40+
this.update(store)
41+
}}},
42+
rows)
43+
)
44+
45+
function updateLabel(v) {
46+
this.setText(v.label)
47+
}
48+
function updateRow(v) {
49+
var className = this.key === store.selected ? "danger" : ""
50+
if (this.node.className !== className) this.node.className = className
51+
this.updateChildren(v)
52+
}
53+
function rowClickHandler(e) {
54+
var key = extra.get(this).key,
55+
tgt = extra.get(e.target),
56+
act = tgt && tgt.key
57+
if (!act) return
58+
59+
e.preventDefault()
60+
time.start(act)
61+
switch (act) {
62+
case 'select':
63+
store.select(key)
64+
break
65+
case 'delete':
66+
store.delete(key)
67+
break
68+
}
69+
table.update(store)
70+
time.stop()
71+
}

pico-dom-v0.18.0/src/time.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*eslint indent:0, quotes:0, no-console:0*/
2+
var startTime
3+
var lastMeasure
4+
5+
module.exports = {
6+
start: function startMeasure(name) {
7+
startTime = performance.now()
8+
lastMeasure = name
9+
},
10+
stop: function stopMeasure() {
11+
var last = lastMeasure
12+
if (lastMeasure) {
13+
window.setTimeout(function () {
14+
lastMeasure = null
15+
var stop = performance.now()
16+
console.log(last+" took "+(stop-startTime))
17+
}, 0)
18+
}
19+
}
20+
}

webdriver-ts/src/common.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export let frameworks = [
6060
f("mithril-v1.0.1", false),
6161
f("nx-v1.0.0-beta.1.1.0-keyed", false),
6262
f("nx-v1.0.0-beta.1.1.0-non-keyed", true),
63+
f("pico-dom-v0.18.0", false),
6364
f("plastiq-v1.33.0", false),
6465
f("polymer-v1.7.0", true, {uri: "polymer-v1.7.0", useShadowRoot: true}),
6566
f("preact-v7.1.0", false),

0 commit comments

Comments
 (0)