-
-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add async benchmark and perf iterations
- Loading branch information
1 parent
45b8e8b
commit 1ac4fc4
Showing
5 changed files
with
98 additions
and
49 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'preact-render-to-string': patch | ||
--- | ||
|
||
Add async benchmarks and iterate on perf improvements |
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,42 @@ | ||
import { h } from 'preact'; | ||
import { lazy } from 'preact/compat'; | ||
|
||
function Leaf() { | ||
return ( | ||
<div> | ||
<span class="foo" data-testid="stack"> | ||
deep stack | ||
</span> | ||
</div> | ||
); | ||
} | ||
|
||
const lazies = new Array(600) | ||
.fill(600) | ||
.map(() => | ||
lazy(() => | ||
Promise.resolve().then(() => ({ | ||
default: (props) => <div>{props.children}</div> | ||
})) | ||
) | ||
); | ||
function PassThrough(props) { | ||
const Lazy = lazies(props.id); | ||
return <Lazy {...props} />; | ||
} | ||
|
||
function recursive(n, m) { | ||
if (n <= 0) { | ||
return <Leaf />; | ||
} | ||
return <PassThrough id={n * m}>{recursive(n - 1)}</PassThrough>; | ||
} | ||
|
||
const content = []; | ||
for (let i = 0; i < 5; i++) { | ||
content.push(recursive(10, i)); | ||
} | ||
|
||
export default function App() { | ||
return <div>{content}</div>; | ||
} |
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,23 +1,35 @@ | ||
import { h } from 'preact'; | ||
import Suite from 'benchmarkjs-pretty'; | ||
import renderToStringBaseline from 'baseline-rts'; | ||
import renderToStringBaseline, { | ||
renderToStringAsync as renderToStringAsyncBaseline | ||
} from 'baseline-rts'; | ||
// import renderToString from '../src/index'; | ||
import renderToString from '../dist/index.module.js'; | ||
import renderToString, { renderToStringAsync } from '../dist/index.module.js'; | ||
import TextApp from './text'; | ||
import StackApp from './stack'; | ||
import { App as IsomorphicSearchResults } from './isomorphic-ui/search-results/index'; | ||
import { App as ColorPicker } from './isomorphic-ui/color-picker'; | ||
|
||
function suite(name, Root) { | ||
return new Suite(name) | ||
.add('baseline', () => renderToStringAsyncBaseline(<Root />)) | ||
.add('current', () => renderToStringAsync(<Root />)) | ||
.run(); | ||
} | ||
|
||
function asyncSuite(name, Root) { | ||
return new Suite(name) | ||
.add('baseline', () => renderToStringBaseline(<Root />)) | ||
.add('current', () => renderToString(<Root />)) | ||
.run(); | ||
} | ||
|
||
(async () => { | ||
await suite('Text', TextApp); | ||
await suite('SearchResults', IsomorphicSearchResults); | ||
await suite('ColorPicker', ColorPicker); | ||
await suite('Stack Depth', StackApp); | ||
// await suite('Text', TextApp); | ||
// await suite('SearchResults', IsomorphicSearchResults); | ||
// await suite('ColorPicker', ColorPicker); | ||
// await suite('Stack Depth', StackApp); | ||
|
||
const { App: Async } = await import('./async.js'); | ||
await asyncSuite('async', Async); | ||
})(); |
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 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