Files
next.js/bench/vercel/bench.js
Arian Tron 61f56f997c
Some checks failed
Test examples / Test Examples (20) (push) Has been cancelled
Test examples / Test Examples (22) (push) Has been cancelled
Lock Threads / action (push) Has been cancelled
Trigger Release / start (push) Has been cancelled
Stale issue handler / stale (push) Has been cancelled
Update Font Data / create-pull-request (push) Has been cancelled
build-and-deploy / deploy-target (push) Has been cancelled
build-and-deploy / build (push) Has been cancelled
build-and-deploy / stable - aarch64-unknown-linux-musl - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-unknown-linux-musl - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-unknown-linux-gnu - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-unknown-linux-gnu - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-pc-windows-msvc - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-pc-windows-msvc - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-apple-darwin - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-apple-darwin - node@16 (push) Has been cancelled
build-and-deploy / build-wasm (nodejs) (push) Has been cancelled
build-and-deploy / build-wasm (web) (push) Has been cancelled
build-and-deploy / Deploy preview tarball (push) Has been cancelled
build-and-deploy / Potentially publish release (push) Has been cancelled
build-and-deploy / publish-turbopack-npm-packages (push) Has been cancelled
build-and-deploy / Deploy examples (push) Has been cancelled
build-and-deploy / thank you, build (push) Has been cancelled
build-and-deploy / Upload Turbopack Bytesize metrics to Datadog (push) Has been cancelled
Rspack Next.js development integration tests / Rspack integration tests (push) Has been cancelled
Rspack Next.js production integration tests / Rspack integration tests (push) Has been cancelled
Turbopack Next.js development integration tests / Next.js integration tests (push) Has been cancelled
Turbopack Next.js production integration tests / Next.js integration tests (push) Has been cancelled
Update Rspack test manifest / Update and upload Rspack development test manifest (push) Has been cancelled
Update Rspack test manifest / Update and upload Rspack production test manifest (push) Has been cancelled
Upload bundler test manifests to areweturboyet.com / Upload test results (push) Has been cancelled
Update React / create-pull-request (push) Has been cancelled
test-e2e-project-reset-cron / reset-test-project (push) Has been cancelled
Notify about the top 15 issues/PRs/feature requests (most reacted) in the last 90 days / run (push) Has been cancelled
first commit
2026-03-10 19:37:31 +03:30

104 lines
2.7 KiB
JavaScript

import { Command } from 'commander'
import console from 'console'
import PQueue from 'p-queue'
import {
generateProjects,
cleanupProjectFolders,
TEST_PROJECT_NAME,
} from './project-utils.js'
import { printBenchmarkResults } from './chart.js'
import { genRetryableRequest } from './gen-request.js'
import { bold, red } from '../../packages/next/dist/lib/picocolors.js'
const program = new Command()
const queue = new PQueue({ concurrency: 50 })
const TTFB_OUTLIERS_THRESHOLD = 1500
let progress = 0
program.option('-p, --path <path>')
program.option('-s, --skip-build', 'Skip build step')
program.option('-f, --force-crash', 'Force function crash')
program.parse(process.argv)
const options = program.opts()
if (options.path) {
console.log('Running benchmark for path: ', options.path)
}
if (options.skipBuild) {
console.log('Skipping build step')
}
if (options.forceCrash) {
console.log('Forcing function crash')
}
export const forceCrash = options.forceCrash
try {
const [originDeploymentURL, headDeploymentURL] = options.skipBuild
? [
`https://${TEST_PROJECT_NAME}-origin.vercel.app`,
`https://${TEST_PROJECT_NAME}-head.vercel.app`,
]
: await generateProjects()
const originBenchmarkURL = `${originDeploymentURL}${options.path || ''}`
const headBenchmarkURL = `${headDeploymentURL}${options.path || ''}`
console.log(`Origin deployment URL: ${originBenchmarkURL}`)
console.log(`Head deployment URL: ${headBenchmarkURL}`)
console.log(`Running benchmark...`)
const benchResults = await runBenchmark(originBenchmarkURL)
const headBenchResults = await runBenchmark(headBenchmarkURL)
console.log(bold('Benchmark results for cold:'))
printBenchmarkResults(
{
origin: benchResults,
head: headBenchResults,
},
(r) => r.cold && r.firstByte <= TTFB_OUTLIERS_THRESHOLD && r.firstByte
)
console.log(bold('Benchmark results for hot:'))
printBenchmarkResults(
{
origin: benchResults,
head: headBenchResults,
},
(r) => !r.cold && r.firstByte <= TTFB_OUTLIERS_THRESHOLD && r.firstByte
)
} catch (err) {
console.log(red('Benchmark failed: ', err))
} finally {
await cleanupProjectFolders()
}
async function runBenchmark(url) {
progress = 0
process.stdout.write(`Sending requests to ${url} ...\n`)
process.stdout.write(`Progress: ${++progress}/500`)
return (
await Promise.all(
Array.from({ length: 500 }).map(async () => {
const p = await queue.add(() => genRetryableRequest(url))
refreshProgress()
return p
})
)
).filter(Boolean)
}
function refreshProgress() {
process.stdout.clearLine()
process.stdout.cursorTo(0)
process.stdout.write(`Requests sent: ${++progress}/500`)
}