Skip to content

Commit 7c39981

Browse files
committed
test: add hydration benchmark for Vapor and VDOM
1 parent 0dc8963 commit 7c39981

File tree

1 file changed

+120
-0
lines changed

1 file changed

+120
-0
lines changed
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
/**
2+
* @vitest-environment jsdom
3+
*/
4+
import { bench, describe } from 'vitest'
5+
import {
6+
ssrInterpolate as _ssrInterpolate,
7+
ssrRenderAttrs as _ssrRenderAttrs,
8+
} from '@vue/server-renderer'
9+
import {
10+
Fragment as _Fragment,
11+
createElementBlock as _createElementBlock,
12+
createElementVNode as _createElementVNode,
13+
openBlock as _openBlock,
14+
renderList as _renderList,
15+
toDisplayString as _toDisplayString,
16+
vModelText as _vModelText,
17+
withDirectives as _withDirectives,
18+
createSSRApp,
19+
ref,
20+
} from '@vue/runtime-dom'
21+
import {
22+
applyTextModel as _applyTextModel,
23+
child as _child,
24+
createFor as _createFor,
25+
renderEffect as _renderEffect,
26+
setInsertionState as _setInsertionState,
27+
setText as _setText,
28+
template as _template,
29+
createVaporSSRApp,
30+
} from '@vue/runtime-vapor'
31+
32+
describe('hydration benchmark', () => {
33+
let html = `<!--[--><h1>Hello World!</h1><input value="Hello World!"><!--]-->`
34+
35+
const t0 = _template('<h1> </h1>')
36+
const t1 = _template('<input>')
37+
38+
const VaporChild = {
39+
__vapor: true,
40+
setup() {
41+
const msg = ref('Hello World!')
42+
43+
const n0 = t0() as any
44+
const n1 = t1() as any
45+
const x0 = _child(n0) as any
46+
_applyTextModel(
47+
n1,
48+
() => msg.value,
49+
_value => (msg.value = _value),
50+
)
51+
_renderEffect(() => _setText(x0, _toDisplayString(msg.value)))
52+
return [n0, n1]
53+
},
54+
}
55+
56+
const VdomChild = {
57+
setup() {
58+
const msg = ref('foo')
59+
60+
// @ts-expect-error
61+
return (_ctx, _cache) => {
62+
return (
63+
_openBlock(),
64+
_createElementBlock(
65+
_Fragment,
66+
null,
67+
[
68+
_createElementVNode(
69+
'h1',
70+
null,
71+
_toDisplayString(msg.value),
72+
1 /* TEXT */,
73+
),
74+
_withDirectives(
75+
_createElementVNode(
76+
'input',
77+
{
78+
'onUpdate:modelValue':
79+
_cache[0] ||
80+
(_cache[0] = ($event: any) => (msg.value = $event)),
81+
},
82+
null,
83+
512 /* NEED_PATCH */,
84+
),
85+
[[_vModelText, msg.value]],
86+
),
87+
],
88+
64 /* STABLE_FRAGMENT */,
89+
)
90+
)
91+
}
92+
},
93+
}
94+
95+
bench('vapor', () => {
96+
try {
97+
__DEV__ = false
98+
const container = document.createElement('div')
99+
container.innerHTML = html
100+
101+
const app = createVaporSSRApp(VaporChild)
102+
app.mount(container)
103+
} finally {
104+
__DEV__ = true
105+
}
106+
})
107+
108+
bench('vdom', () => {
109+
try {
110+
__DEV__ = false
111+
const container = document.createElement('div')
112+
container.innerHTML = html
113+
114+
const app = createSSRApp(VdomChild)
115+
app.mount(container)
116+
} finally {
117+
__DEV__ = true
118+
}
119+
})
120+
})

0 commit comments

Comments
 (0)