<script src="https://raw.githack.com/solidjs-web/SolidJS-Web/5e863b29b7c6153b8466900bd9f66d5c9386e0b1/dist/solid-js-dev.js"></script>
const { createSignal, html, render } = SolidJS;
const App = () => {
const [counter, setCounter] = createSignal(0);
setInterval(() => setCounter(c => c + 1), 1000);
return html`<div>${() => counter()}</div>`;
}
App();
const { createSignal, h, render } = SolidJS;
const App = () => {
const [counter, setCounter] = createSignal(0);
setInterval(() => setCounter(c => c + 1), 1000);
return h('div', () => counter());
}
App();
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
html | |
h |
Test name | Executions per second |
---|---|
html | 98242.5 Ops/sec |
h | 104410.4 Ops/sec |
The benchmark being tested on MeasureThat.net is a performance comparison between two rendering approaches in SolidJS, a reactive JavaScript library for building user interfaces. The two approaches compared are:
html
function.h
function to create virtual DOM elements directly.Using html
Function
return html`<div>${() => counter()}</div>`;
Using h
Function
h
function is explicitly called to create the virtual DOM element:return h('div', () => counter());
html
Function:
Pros:
Cons:
h
Function:
Pros:
Cons:
h
function's structure.h
method shows better performance with higher executions per second compared to the html
method.Apart from SolidJS, several other JavaScript libraries and frameworks offer similar component-based approaches with varying advantages:
html
and h
in terms of syntax.Choosing between these alternatives would largely depend on project requirements, team familiarity, and the specific performance characteristics desired.