Skip to content

Commit

Permalink
add bench setup
Browse files Browse the repository at this point in the history
  • Loading branch information
feedthejim committed Oct 11, 2022
1 parent 3c8727d commit 86e94fe
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 0 deletions.
10 changes: 10 additions & 0 deletions bench/minimal-server/benchmark-app/app/layout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import * as React from 'react'

export default function Root({ children }) {
return (
<html>
<head></head>
<body>{children}</body>
</html>
)
}
5 changes: 5 additions & 0 deletions bench/minimal-server/benchmark-app/app/rsc/page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import * as React from 'react'

export default function page() {
return <div>hello</div>
}
5 changes: 5 additions & 0 deletions bench/minimal-server/benchmark-app/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
experimental: {
appDir: true,
},
}
14 changes: 14 additions & 0 deletions bench/minimal-server/benchmark-app/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "stats-app",
"private": true,
"license": "MIT",
"dependencies": {
"webpack-bundle-analyzer": "^4.6.1",
"webpack-stats-plugin": "^1.1.0"
},
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start"
}
}
9 changes: 9 additions & 0 deletions bench/minimal-server/benchmark-app/pages/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import * as React from 'react'

export default function page() {
return <div> hello world </div>
}

export async function getServerSideProps() {
return {}
}
7 changes: 7 additions & 0 deletions bench/minimal-server/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "next-minimal-server",
"description": "Minimal server for Next.js for benchmarking/perf analysis purposes.",
"scripts": {
"start": "node start.js"
}
}
40 changes: 40 additions & 0 deletions bench/minimal-server/run.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
process.env.__NEXT_REACT_CHANNEL = 'exp'
process.env.NODE_ENV = 'production'

require('../../test/lib/react-channel-require-hook')

console.time('next-cold-start')
const NextServer = require('next/dist/server/next-server').default
const path = require('path')

const appDir = path.join(__dirname, 'benchmark-app')
const distDir = '.next'

const compiledConfig = require(path.join(
appDir,
distDir,
'required-server-files.json'
)).config

process.chdir(appDir)

const nextServer = new NextServer({
conf: compiledConfig,
dir: appDir,
distDir,
minimalMode: true,
customServer: false,
})

const requestHandler = nextServer.getRequestHandler()

require('http')
.createServer((req, res) => {
console.time('next-request')
return requestHandler(req, res).finally(() => {
console.timeEnd('next-request')
})
})
.listen(3000, () => {
console.timeEnd('next-cold-start')
})

0 comments on commit 86e94fe

Please sign in to comment.