import Benchmark from 'benchmark'
import Nano, { Fragment as NanoFragment } from 'nano-jsx'
import * as Preact from 'preact'
import { render as renderByPreact } from 'preact-render-to-string'
import React from 'react'
import { renderToString as renderByReact } from 'react-dom/server'
import * as HonoJSX from '../../src/middleware/jsx'
const buildPage = ({ jsx, Fragment }: { jsx: any; Fragment: any }) => {
const Content = () => (
<>
1
a
2
b
3
c' }} />
{null}
{undefined}
>
)
const Form = () => (
)
return () => (
)
}
const PageByHonoJSX = buildPage(HonoJSX)
const PageByReact = buildPage({ jsx: React.createElement, Fragment: React.Fragment })
const PageByNano = buildPage({ jsx: Nano.h, Fragment: NanoFragment })
const PageByPreact = buildPage({ jsx: Preact.h, Fragment: Preact.Fragment })
const suite = new Benchmark.Suite()
suite
.add('Hono', () => {
PageByHonoJSX().toString()
})
.add('React', () => {
renderByReact(PageByReact())
})
.add('Preact', () => {
renderByPreact(PageByPreact())
})
.add('Nano', () => {
Nano.renderSSR(PageByNano)
})
.on('cycle', (ev: any) => {
console.log(String(ev.target))
})
.on('complete', (ev: any) => {
console.log(`Fastest is ${ev.currentTarget.filter('fastest').map('name')}`)
})
.run({ async: true })