forked from nicojs/typed-html
-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c55e506
commit 085fd0b
Showing
18 changed files
with
2,477 additions
and
359 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,76 @@ | ||
import { createWriteStream } from 'fs'; | ||
import { HelloWorld } from './renderers/hello-world'; | ||
import { ManyComponents } from './renderers/many-components'; | ||
import { ManyProps } from './renderers/many-props'; | ||
import { MdnHomepage } from './renderers/mdn-homepage'; | ||
import { bench } from './suite'; | ||
|
||
function toMdRow(values: string[]) { | ||
return '| ' + values.join(' | ') + ' |'; | ||
} | ||
|
||
(async () => { | ||
const out = createWriteStream('benchmark.md', { | ||
mode: 0o644, | ||
flags: 'w' | ||
}); | ||
|
||
out.write('# Benchmark\n\n'); | ||
|
||
out.write('- ' + new Date().toISOString() + '\n'); | ||
out.write('- Node: ' + process.version + '\n'); | ||
out.write('- V8: ' + process.versions.v8 + '\n'); | ||
out.write('- OS: ' + process.platform + '\n'); | ||
out.write('- Arch: ' + process.arch + '\n'); | ||
out.write('\n'); | ||
|
||
for (const [name, fn] of [ | ||
['Hello World', HelloWorld], | ||
['Mdn Homepage', MdnHomepage], | ||
['Many Props', ManyProps], | ||
['Many Components', ManyComponents] | ||
] as const) { | ||
out.write('## ' + name + '\n\n'); | ||
|
||
let start = true; | ||
|
||
for (const runs of [10, 10_000, 100_000]) { | ||
console.log(name, runs); | ||
|
||
const res = bench(name, runs, fn); | ||
|
||
if (start) { | ||
out.write(toMdRow(Object.keys(res)) + '\n'); | ||
out.write(toMdRow(Object.keys(res).fill('-')) + '\n'); | ||
start = false; | ||
} | ||
|
||
out.write(toMdRow(Object.values(bench(name, runs, fn))) + '\n'); | ||
|
||
await new Promise((resolve) => setTimeout(resolve, 1000)); | ||
gc!(); | ||
} | ||
|
||
out.write('\n'); | ||
} | ||
})().catch(console.error); | ||
//@ts-nocheck - disable messing with source types | ||
|
||
/// <reference path="../jsx.d.ts" /> | ||
/// <reference path="../index.d.ts" /> | ||
/// <reference path="../all-types.d.ts" /> | ||
|
||
import assert from 'assert'; | ||
import { bench, group, run } from 'mitata'; | ||
import { ManyComponents, TemplateManyComponents } from './renderers/many-components.js'; | ||
import { ManyProps, TemplateManyProps } from './renderers/many-props.js'; | ||
import { MdnHomepage, TemplateMdnHomepage } from './renderers/mdn-homepage.js'; | ||
|
||
process.env.NODE_ENV = 'production'; | ||
|
||
//@ts-expect-error - dynamic import from cjs js file. | ||
const KitaHtml = (await import('../../index.js')).default; | ||
const TypedHtml = await import('typed-html'); | ||
const React = await import('react'); | ||
const ReactDOMServer = await import('react-dom/server'); | ||
const CommonTags = await import('common-tags'); | ||
|
||
// Ensures that Kitajs/html and react produce the same output | ||
assert.equal( | ||
ReactDOMServer.renderToStaticMarkup(ManyComponents(React, 'Hello World!') as any), | ||
// Simply removes spaces and newlines | ||
ManyComponents(KitaHtml, 'Hello World!') | ||
); | ||
|
||
// Ensures that Kitajs/html and common-tags produce the same output | ||
assert.equal( | ||
ManyComponents(KitaHtml, 'Hello World!'), | ||
// Simply removes spaces and newlines | ||
TemplateManyComponents(CommonTags.html, 'Hello World!') | ||
.split('\n') | ||
.map((l: string) => l.trim()) | ||
.join('') | ||
); | ||
|
||
// Kitajs/html and typed html does produces the same output, however typed-html appends spaces between tags | ||
assert.equal( | ||
ManyComponents(KitaHtml, 'Hello World!'), | ||
// Simply removes spaces and newlines | ||
ManyComponents(TypedHtml, 'Hello World!') | ||
.toString() | ||
.replace(/< \//g, '</') | ||
.replace(/\n/g, '') | ||
); | ||
|
||
group('Many Components (31.4kb)', () => { | ||
bench('Typed Html', () => ManyComponents(TypedHtml, 'Hello World!')); | ||
bench('KitaJS/Html', () => ManyComponents(KitaHtml, 'Hello World!')); | ||
bench('Common Tags', () => TemplateManyComponents(CommonTags.html, 'Hello World!')); | ||
bench('React', () => | ||
ReactDOMServer.renderToStaticMarkup(ManyComponents(React, 'Hello World!') as any) | ||
); | ||
}); | ||
|
||
group('MdnHomepage (66.7Kb)', () => { | ||
bench('Typed Html', () => MdnHomepage(TypedHtml, 'Hello World!')); | ||
bench('KitaJS/Html', () => MdnHomepage(KitaHtml, 'Hello World!')); | ||
bench('Common Tags', () => TemplateMdnHomepage(CommonTags.html, 'Hello World!')); | ||
bench('React', () => | ||
ReactDOMServer.renderToStaticMarkup(MdnHomepage(React, 'Hello World!') as any) | ||
); | ||
}); | ||
|
||
group('Many Props (7.4kb)', () => { | ||
bench('Typed Html', () => ManyProps(TypedHtml, 'Hello World!')); | ||
bench('KitaJS/Html', () => ManyProps(KitaHtml, 'Hello World!')); | ||
bench('Common Tags', () => TemplateManyProps(CommonTags.html, 'Hello World!')); | ||
bench('React', () => | ||
ReactDOMServer.renderToStaticMarkup(ManyProps(React, 'Hello World!') as any) | ||
); | ||
}); | ||
|
||
run().catch(console.error); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"type": "module" | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.