Skip to content

Commit 8000ee7

Browse files
authored
Merge pull request krausest#1 from krausest/master
Rebase
2 parents 78b34d5 + 58fe0b5 commit 8000ee7

File tree

23 files changed

+445
-413
lines changed

23 files changed

+445
-413
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,11 @@ Contributions are very welcome. Please use the following rules:
239239
* You can assert the correct keyed or non-keyed behaviour by using the isKeyed test tool. cd to webdriver-ts and call it like `npm run isKeyed -- --framework [your framework]`. It'll print an error if your framework behaves other as specified.
240240
* Please don't commit any of the result file webdriver-ts/table.html, webdriver-ts-results/src/results.ts or webdriver-ts-results/table.html. I use to run the benchmarks after merging and publish updated (temporary) results.
241241
* The latest stable chrome can be used regarding web features and language level (babel-preset-env "last 1 chrome versions")
242+
* **Please don't over-optimize. Other contributors will review your implementation so beware of discussions ([#521](https://github.com/krausest/js-framework-benchmark/pull/521), [#519](https://github.com/krausest/js-framework-benchmark/pull/519), [#430](https://github.com/krausest/js-framework-benchmark/issues/430)) and rejection if the community finds you cheating. When are you safe?**
243+
* If the initial rendering is able to render the selection state
244+
* The implementation uses only the idiomatic style of its library
245+
* If you don't use userland hacks in your implementation like dom manipulations or request animation frame calls
246+
Tip: If you start with your implementation do not take vanillajs as the reference. It violates those rules and serves only as a performance baseline and not as a best practice implementation.
242247
243248
This work is derived from a benchmark that Richard Ayotte published on https://gist.github.com/RichAyotte/a7b8780341d5e75beca7 and adds more framework and more operations. Thanks for the great work.
244249

frameworks/keyed/ko-jsx/package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "js-framework-benchmark-ko-jsx",
3-
"version": "0.3.0",
3+
"version": "0.4.0",
44
"main": "index.js",
55
"js-framework-benchmark": {
66
"frameworkVersionFromPackage": "ko-jsx"
@@ -17,16 +17,16 @@
1717
"url": "https://github.com/krausest/js-framework-benchmark.git"
1818
},
1919
"dependencies": {
20-
"babel-plugin-jsx-dom-expressions": "0.3.6",
20+
"babel-plugin-jsx-dom-expressions": "0.4.3",
2121
"knockout": "^3.4.2",
22-
"ko-jsx": "0.3.0"
22+
"ko-jsx": "0.4.0"
2323
},
2424
"devDependencies": {
25-
"@babel/core": "7.2.2",
26-
"rollup": "1.0.0",
27-
"rollup-plugin-babel": "4.2.0",
25+
"@babel/core": "7.3.3",
26+
"rollup": "1.1.2",
27+
"rollup-plugin-babel": "4.3.2",
2828
"rollup-plugin-commonjs": "9.2.0",
2929
"rollup-plugin-node-resolve": "4.0.0",
30-
"rollup-plugin-terser": "4.0.1"
30+
"rollup-plugin-terser": "4.0.4"
3131
}
3232
}

frameworks/keyed/ko-jsx/src/Main.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,18 @@ var HomeViewModel = function () {
9090
// stopMeasure();
9191
};
9292

93-
self.clickRow = function(e, id, action) {
94-
if (action === 'remove') {
95-
// startMeasure("delete");
96-
var tmp = self.data();
97-
const idx = tmp.findIndex(d => d.id === id);
98-
self.data.splice(idx, 1);
99-
// stopMeasure();
100-
} else {
101-
// startMeasure("select");
102-
self.selected(id);
103-
// stopMeasure();
104-
}
93+
self.select = function(e, id) {
94+
// startMeasure("select");
95+
self.selected(id);
96+
// stopMeasure();
97+
}
98+
99+
self.remove = function(e, id) {
100+
// startMeasure("delete");
101+
var tmp = self.data();
102+
const idx = tmp.findIndex(d => d.id === id);
103+
self.data.splice(idx, 1);
104+
// stopMeasure();
105105
}
106106
};
107107

frameworks/keyed/ko-jsx/src/template.jsx

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { r, selectWhen } from 'ko-jsx'
22

33
const Button = ({id, text, fn}) =>
4-
<div class ='col-sm-6 smallpad'>
4+
<div class='col-sm-6 smallpad'>
55
<button id={id} class='btn btn-primary btn-block' type='button' onClick={fn}>{text}</button>
66
</div>
77

8-
export default function({data, selected, run, runLots, add, update, clear, swapRows, clickRow}) {
8+
export default function({data, selected, run, runLots, add, update, clear, swapRows, remove, select}) {
99
return <div class='container'>
1010
<div class='jumbotron'><div class='row'>
11-
<div class ='col-md-6'><h1>KnockoutJSX-keyed</h1></div>
12-
<div class ='col-md-6'><div class ='row'>
11+
<div class='col-md-6'><h1>KnockoutJSX-keyed</h1></div>
12+
<div class='col-md-6'><div class='row'>
1313
<Button id='run' text='Create 1,000 rows' fn={run} />
1414
<Button id='runlots' text='Create 10,000 rows' fn={runLots} />
1515
<Button id='add' text='Append 1,000 rows' fn={add} />
@@ -18,15 +18,14 @@ export default function({data, selected, run, runLots, add, update, clear, swapR
1818
<Button id='swaprows' text='Swap Rows' fn={swapRows} />
1919
</div></div>
2020
</div></div>
21-
<table class='table table-hover table-striped test-data'><tbody onClick={clickRow}>
22-
<$ each={data()} afterRender={selectWhen(selected, 'danger')}>{
23-
row =>
24-
<tr model={row.id}>
25-
<td class='col-md-1' textContent={row.id} />
26-
<td class='col-md-4'><a>{row.label}</a></td>
27-
<td class='col-md-1'><a action={'remove'}><span class='glyphicon glyphicon-remove' /></a></td>
28-
<td class='col-md-6'/>
29-
</tr>
21+
<table class='table table-hover table-striped test-data'><tbody>
22+
<$ each={data()} afterRender={selectWhen(selected, 'danger')}>{ row =>
23+
<tr model={row.id}>
24+
<td class='col-md-1' textContent={row.id} />
25+
<td class='col-md-4'><a onClick={select}>{row.label}</a></td>
26+
<td class='col-md-1'><a onClick={remove}><span class='glyphicon glyphicon-remove' /></a></td>
27+
<td class='col-md-6'/>
28+
</tr>
3029
}</$>
3130
</tbody></table>
3231
<span class='preloadicon glyphicon glyphicon-remove' aria-hidden="true" />

frameworks/keyed/lighterhtml/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
},
2525
"homepage": "https://github.com/krausest/js-framework-benchmark#readme",
2626
"dependencies": {
27-
"lighterhtml": "0.8.10"
27+
"lighterhtml": "0.9.0"
2828
},
2929
"devDependencies": {
3030
"@babel/core": "^7.2.2",

frameworks/keyed/lighterhtml/rollup.config.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,7 @@ export default {
1414
delimiters: ['', '']
1515
}),
1616
babel({
17-
plugins: [
18-
['remove-ungap', {
19-
exclude: [
20-
'@ungap/create-content'
21-
]
22-
}]
23-
],
17+
plugins: [['remove-ungap']]
2418
}),
2519
terser()
2620
],

frameworks/keyed/lit-html/src/index.js

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { html, render } from '../node_modules/lit-html/lit-html.js';
22
import { repeat } from '../node_modules/lit-html/directives/repeat.js';
3-
import { guard } from '../node_modules/lit-html/directives/guard.js';
43

54
const adjectives = [
65
'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'];
@@ -28,49 +27,46 @@ const clear = () => {
2827
_render();
2928
};
3029
const interact = e => {
31-
const interaction = e.target.getAttribute('data-interaction');
32-
const id = parseInt(
33-
e.target.parentNode.id ||
34-
e.target.parentNode.parentNode.id ||
35-
e.target.parentNode.parentNode.parentNode.id
36-
);
30+
const td = e.target.closest('td');
31+
const interaction = td.getAttribute('data-interaction');
32+
const id = parseInt(td.parentNode.id);
3733
if (interaction === 'delete') {
38-
del(id)
34+
del(id);
3935
} else {
40-
select(id)
36+
select(id);
4137
}
4238
};
4339
const del = id => {
4440
const idx = data.findIndex(d => d.id === id);
45-
data.splice(idx, 1)
41+
data.splice(idx, 1);
4642
_render();
4743
};
4844
const select = id => {
4945
if (selected > -1) {
50-
data[selected] = { ...data[selected], selected: false }
46+
data[selected].selected = false;
5147
}
5248
selected = data.findIndex(d => d.id === id);
53-
data[selected] = { ...data[selected], selected: true }
49+
data[selected].selected = true;
5450
_render();
5551
};
5652
const swapRows = () => {
5753
if (data.length > 998) {
58-
const tmp = data[1]
59-
data[1] = data[998]
60-
data[998] = tmp
54+
const tmp = data[1];
55+
data[1] = data[998];
56+
data[998] = tmp;
6157
}
6258
_render();
6359
};
6460
const update = () => {
65-
for(let i = 0; i < data.length; i += 10) {
66-
const item = data[i]
67-
data[i] = { ...item, label: item.label + ' !!!' }
61+
for (let i = 0; i < data.length; i += 10) {
62+
const item = data[i];
63+
data[i].label += ' !!!';
6864
}
6965
_render();
7066
};
7167
const buildData = count => {
7268
const data = [];
73-
for (var i = 0; i < count; i++) {
69+
for (let i = 0; i < count; i++) {
7470
data.push({
7571
id: did++,
7672
label: `${adjectives[_random(adjectives.length)]} ${colours[_random(colours.length)]} ${nouns[_random(nouns.length)]}`,
@@ -126,20 +122,19 @@ const template = () => html`
126122
<table @click=${interact} class="table table-hover table-striped test-data">
127123
<tbody>${repeat(data,
128124
item => item.id,
129-
item => guard(item, () => html`
125+
item => html`
130126
<tr id=${item.id} class=${item.selected ? 'danger' : ''}>
131127
<td class="col-md-1">${item.id}</td>
132-
<td data-interaction='select' class="col-md-4">
133-
<a data-interaction='select'>${item.label}</a>
128+
<td class="col-md-4">
129+
<a>${item.label}</a>
134130
</td>
135131
<td data-interaction='delete' class="col-md-1">
136-
<a data-interaction='delete'>
137-
<span data-interaction='delete' class="glyphicon glyphicon-remove" aria-hidden="true"></span>
132+
<a>
133+
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
138134
</a>
139135
</td>
140136
<td class="col-md-6"></td>
141-
</tr>`)
142-
)}
137+
</tr>`)}
143138
</tbody>
144139
</table>
145140
<span class="preloadicon glyphicon glyphicon-remove" aria-hidden="true"></span>

frameworks/keyed/mobx-jsx/package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "js-framework-benchmark-mobx-jsx",
3-
"version": "0.1.0",
3+
"version": "0.2.0",
44
"main": "dist/main.js",
55
"js-framework-benchmark": {
66
"frameworkVersionFromPackage": "mobx-jsx"
@@ -17,16 +17,16 @@
1717
"url": "https://github.com/krausest/js-framework-benchmark.git"
1818
},
1919
"dependencies": {
20-
"babel-plugin-jsx-dom-expressions": "0.3.6",
21-
"mobx": "5.8.0",
22-
"mobx-jsx": "0.1.0"
20+
"babel-plugin-jsx-dom-expressions": "0.4.3",
21+
"mobx": "5.9.0",
22+
"mobx-jsx": "0.2.0"
2323
},
2424
"devDependencies": {
25-
"@babel/core": "7.2.2",
26-
"rollup": "1.0.0",
27-
"rollup-plugin-babel": "4.2.0",
25+
"@babel/core": "7.3.3",
26+
"rollup": "1.1.2",
27+
"rollup-plugin-babel": "4.3.2",
2828
"rollup-plugin-node-resolve": "4.0.0",
2929
"rollup-plugin-replace": "^2.1.0",
30-
"rollup-plugin-terser": "4.0.1"
30+
"rollup-plugin-terser": "4.0.4"
3131
}
3232
}

frameworks/keyed/mobx-jsx/src/main.jsx

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,20 @@ function buildData(count) {
2222
}
2323

2424
const Button = ({ id, text, fn }) =>
25-
<div class ='col-sm-6 smallpad'>
25+
<div class='col-sm-6 smallpad'>
2626
<button id={ id } class='btn btn-primary btn-block' type='button' onClick={ fn }>{ text }</button>
2727
</div>
2828

2929
const App = () => {
3030
const state = observable({data: [], selected: null});
3131

32-
const clickRow = (e, id, intent) => {
33-
action(() => {
34-
if (intent === 'remove') {
35-
const data = state.data.slice(0);
36-
data.splice(data.findIndex(d => d.id === id), 1)
37-
state.data = data;
38-
} else state.selected = id;
39-
})();
40-
};
32+
const remove = (e, id) => action(() => {
33+
const data = state.data.slice(0);
34+
data.splice(data.findIndex(d => d.id === id), 1)
35+
state.data = data;
36+
})();
37+
38+
const select = (e, id) => action(() => state.selected = id)();
4139

4240
const run = action(e => {
4341
state.data = buildData(1000);
@@ -77,8 +75,8 @@ const App = () => {
7775

7876
return <div class='container'>
7977
<div class='jumbotron'><div class='row'>
80-
<div class ='col-md-6'><h1>MobX-JSX Keyed</h1></div>
81-
<div class ='col-md-6'><div class ='row'>
78+
<div class='col-md-6'><h1>MobX-JSX Keyed</h1></div>
79+
<div class='col-md-6'><div class='row'>
8280
<Button id='run' text='Create 1,000 rows' fn={ run } />
8381
<Button id='runlots' text='Create 10,000 rows' fn={ runLots } />
8482
<Button id='add' text='Append 1,000 rows' fn={ add } />
@@ -87,15 +85,14 @@ const App = () => {
8785
<Button id='swaprows' text='Swap Rows' fn={ swapRows } />
8886
</div></div>
8987
</div></div>
90-
<table class='table table-hover table-striped test-data'><tbody onClick={ clickRow }>
91-
<$ each={ state.data } afterRender={selectWhen(() => state.selected, 'danger')}>{
92-
row =>
93-
<tr model={ row.id }>
94-
<td class='col-md-1' textContent={ row.id } />
95-
<td class='col-md-4'><a>{( row.label )}</a></td>
96-
<td class='col-md-1'><a action={'remove'}><span class='glyphicon glyphicon-remove' /></a></td>
97-
<td class='col-md-6'/>
98-
</tr>
88+
<table class='table table-hover table-striped test-data'><tbody>
89+
<$ each={ state.data } afterRender={selectWhen(() => state.selected, 'danger')}>{ row =>
90+
<tr model={ row.id }>
91+
<td class='col-md-1' textContent={ row.id } />
92+
<td class='col-md-4'><a onClick={ select }>{( row.label )}</a></td>
93+
<td class='col-md-1'><a onClick={ remove }><span class='glyphicon glyphicon-remove' /></a></td>
94+
<td class='col-md-6'/>
95+
</tr>
9996
}</$>
10097
</tbody></table>
10198
<span class='preloadicon glyphicon glyphicon-remove' aria-hidden="true" />

frameworks/keyed/solid/package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "js-framework-benchmark-solid",
3-
"version": "0.3.4",
3+
"version": "0.4.0",
44
"main": "dist/main.js",
55
"js-framework-benchmark": {
66
"frameworkVersionFromPackage": "solid-js"
@@ -17,14 +17,14 @@
1717
"url": "https://github.com/krausest/js-framework-benchmark.git"
1818
},
1919
"dependencies": {
20-
"babel-plugin-jsx-dom-expressions": "0.3.6",
21-
"solid-js": "0.3.4"
20+
"babel-plugin-jsx-dom-expressions": "0.4.3",
21+
"solid-js": "0.4.0"
2222
},
2323
"devDependencies": {
24-
"@babel/core": "7.2.2",
25-
"rollup": "1.0.0",
26-
"rollup-plugin-babel": "4.2.0",
24+
"@babel/core": "7.3.3",
25+
"rollup": "1.1.2",
26+
"rollup-plugin-babel": "4.3.2",
2727
"rollup-plugin-node-resolve": "4.0.0",
28-
"rollup-plugin-terser": "4.0.1"
28+
"rollup-plugin-terser": "4.0.4"
2929
}
3030
}

0 commit comments

Comments
 (0)