/
benchmark.js
79 lines (68 loc) · 1.81 KB
/
benchmark.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
77
78
import { bench } from '../benchmark';
import { html, render, r, Template } from '../src/html';
import hyperHTML from 'hyperhtml';
import {html as litHtml, render as litRender} from 'lit-html';
describe('benchmark', () => {
const getContainer = () => document.createElement('div');
const setupDataHyper = [{
name: 'toFragmentHyper',
fn: (scope) => hyperHTML(document.createDocumentFragment())`
<div></div>
`
}, {
name: 'toContainerHyper',
fn: (scope) => hyperHTML(getContainer())`
<div></div>
`
}];
const setupDataLitHtml = [{
name: 'toFragmentLit',
fn: (scope) => litRender(litHtml`
<div></div>
`, document.createDocumentFragment())
}, {
name: 'toContainerLit',
fn: (scope) => litRender(litHtml`
<div></div>
`, getContainer())
}];
const setupData = [{
name: 'toFragment',
fn: (scope) => r`
<div></div>
`
}, {
name: 'toFragmentSetArg',
fn: (scope) => r`
<div attr=${scope}></div>
`
}, {
name: 'toContainer',
fn: (scope) => render(html`
<div></div>
`, getContainer())
}, {
name: 'toContainerSetArg',
fn: (scope) => render(html`
<div attr=${scope}></div>
`, getContainer())
}];
describe('modulor-html', () => {
setupData.forEach(item => {
const result = bench(item.fn);
it(`${item.name}: ${result.hz} ops/sec`, () => expect(true).toBe(true));
});
});
describe('hyper-html', () => {
setupDataHyper.forEach(item => {
const result = bench(item.fn);
it(`${item.name}: ${result.hz} ops/sec`, () => expect(true).toBe(true));
});
});
describe('lit-html', () => {
setupDataLitHtml.forEach(item => {
const result = bench(item.fn);
it(`${item.name}: ${result.hz} ops/sec`, () => expect(true).toBe(true));
});
});
});