-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.js
164 lines (122 loc) · 3.04 KB
/
demo.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
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
156
157
158
159
160
161
162
163
164
import React from 'react';
import ReactDOM from 'react-dom';
import MarkdownWasm from './';
import MarkdownIt from 'markdown-it';
class Markdown extends React.PureComponent {
constructor(props) {
super(props);
this.state = {
md: new MarkdownIt(),
};
}
render() {
const { children } = this.props;
const { md } = this.state;
const mdText = md.render(children);
return <div dangerouslySetInnerHTML={ {__html: mdText } } />;
}
}
const corpus = `
# Header
## Header
### Header
#### Header
##### Header
###### Header
---
**This is bold text**
__This is bold text__
*This is italic text*
_This is italic text_
> Blockquotes can also be nested...
>> ...by using additional greater-than signs right next to each other...
> > > ...or with spaces between arrows.
+ Create a list by starting a line with \`+\`, \`-\`, or \`*\`
+ Sub-lists are made by indenting 2 spaces:
- Marker character change forces new list start:
* Ac tristique libero volutpat at
+ Facilisis in pretium nisl aliquet
- Nulla volutpat aliquam velit
+ Very easy!
1. Lorem ipsum dolor sit amet
2. Consectetur adipiscing elit
3. Integer molestie lorem at massa
1. You can use sequential numbers...
1. ...or keep all the numbers as \`1.\`
Start numbering with offset:
57. foo
1. bar
Inline \`code\`
Indented code
// Some comments
line 1 of code
line 2 of code
line 3 of code
Block code "fences"
\`\`\`
Sample text here...
\`\`\`
[SpiderOak](http://spideroak.com)
`;
function range(n) {
const l = [];
for (let i = 0; i < n; i++) {
l.push(i);
}
return l;
}
class Timer extends React.PureComponent {
componentWillMount() {
this.t0 = performance.now();
}
componentDidMount() {
const { end } = this.props;
console.log('rendering', this.displayName, 'took', performance.now() - this.t0, 'ms');
}
}
class MarkdownItTimer extends Timer {
displayName = 'MarkdownItTimer';
render() {
return <td>{ range(100).map( i => <Markdown key={ i }>{ corpus }</Markdown> ) }</td>;
}
}
class MarkdownWasmTimer extends Timer {
displayName = 'MarkdownWasmTimer';
render() {
return <td>{ range(100).map( i => <MarkdownWasm key={ i }>{ corpus }</MarkdownWasm> ) }</td>;
}
}
class Perf extends React.PureComponent {
constructor(props) {
super(props);
this.state = {
showing: true,
Component: MarkdownWasmTimer,
}
}
startBench = Component => () => {
this.setState({
showing: false,
});
setTimeout(() => {
this.setState({
showing: true,
Component,
});
}, 200);
}
render() {
const { showing, Component } = this.state;
return <div>
<button onClick={ this.startBench(MarkdownItTimer) }>Bench markdown-it</button>
<button onClick={ this.startBench(MarkdownWasmTimer) }>Bench react-markdown-wasm</button>
<div>
{ showing && <Component /> }
</div>
</div>;
}
}
window.addEventListener('load', function() {
const content = document.getElementById('content');
ReactDOM.render(<Perf />, content);
});