Commit ebb39797 authored by Tim Neutkens's avatar Tim Neutkens Committed by Guillermo Rauch

Add benchmarks for server rendering (#1294)

* Add benchmarks for server rendering

* Remove bench from flyfile
parent b3743146
import { resolve } from 'path'
import build from '../server/build'
import { render as _render } from '../server/render'
import Benchmark from 'benchmark'
const dir = resolve(__dirname, 'fixtures', 'basic')
const suite = new Benchmark.Suite('Next.js')
suite
.on('start', async () => build(dir))
.add('Tiny stateless component', async p => {
await render('/stateless')
p.resolve()
}, { defer: true })
.add('Big stateless component', async p => {
await render('/stateless-big')
p.resolve()
}, { defer: true })
.add('Stateful component with a loooot of css', async p => {
await render('/css')
p.resolve()
}, { defer: true })
module.exports = suite
function render (url, ctx) {
return _render(url, ctx, { dir, staticMarkup: true })
}
{
"name": "next-bench",
"scripts": {
"build": "next build",
"start": "npm run build && next start",
"bench:stateless": "ab -c1 -n3000 http://0.0.0.0:3000/stateless",
"bench:stateless-big": "ab -c1 -n500 http://0.0.0.0:3000/stateless-big"
}
}
import React from 'react'
export default () => <h1>My component!</h1>
# Next.js server-side benchmarks
## Installation
Follow the steps in [contributing.md](../contributing.md)
Both benchmarks use `ab`. So make sure you have that installed.
## Usage
Before running the test:
```
npm run start
```
Then run one of these tests:
- Stateless application which renders `<h1>My component!</h1>`. Runs 3000 http requests.
```
npm run bench:stateless
```
- Stateless application which renders `<li>This is row {i}</li>` 10.000 times. Runs 500 http requests.
```
npm run bench:stateless-big
```
......@@ -44,18 +44,6 @@ export async function build(fly) {
await fly.serial(['copy', 'compile'])
}
export async function bench(fly) {
await fly.parallel(['compile', 'copy'])
// copy bench fixtures
await fly.source('bench/fixtures/**/*').target('dist/bench/fixtures')
// compile bench
await fly.source('bench/*.js').babel().target('dist/bench')
notify('Compiled bench files')
// yield fly.source('dist/bench/*.js').benchmark({
// benchmark.reporters.etalon('RegExp#test')
// })
}
export default async function (fly) {
await fly.start('build')
await fly.watch('bin/*', 'bin')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment