Skip to content

Commit

Permalink
feat: cli
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz committed Aug 6, 2024
1 parent e81132f commit 11e43bb
Showing 1 changed file with 50 additions and 10 deletions.
60 changes: 50 additions & 10 deletions benchmark/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,56 @@

// @ts-check
import path from 'node:path'
import { parseArgs } from 'node:util'
import connect from 'connect'
import Vue from '@vitejs/plugin-vue'
import { build } from 'vite'
import { exec } from '../scripts/utils.js'
import sirv from 'sirv'
import { launch } from 'puppeteer'
import colors from 'picocolors'

const {
values: { skipVapor, skipApp, port: portStr, count: countStr, headless },
} = parseArgs({
allowPositionals: true,
options: {
skipVapor: {
type: 'boolean',
short: 'v',
},
skipApp: {
type: 'boolean',
short: 'a',
},
port: {
type: 'string',
short: 'p',
default: '8193',
},
count: {
type: 'string',
short: 'c',
default: '100',
},
headless: {
type: 'boolean',
short: 'h',
default: true,
},
},
})

const PORT = 8193
const port = +(/** @type {string}*/ (portStr))
const count = +(/** @type {string}*/ (countStr))

if (!skipVapor) {
await buildVapor()
}
if (!skipApp) {
await buildApp()
}

await buildVapor()
await buildApp()
const server = startServer()
await bench()
server.close()
Expand All @@ -22,7 +61,8 @@ process.on('SIGTERM', () => {
})

async function buildVapor() {
console.info('Building Vapor...')
console.info(colors.blue('Building Vapor...'))

const options = {
cwd: path.resolve(import.meta.dirname, '..'),
stdio: 'inherit',
Expand Down Expand Up @@ -50,7 +90,7 @@ async function buildVapor() {
}

async function buildApp() {
console.info('Building app...')
console.info(colors.blue('\nBuilding app...\n'))

process.env.NODE_ENV = 'production'
const CompilerSFC = await import(
Expand Down Expand Up @@ -87,8 +127,8 @@ async function buildApp() {
}

function startServer() {
const server = connect().use(sirv('./client/dist')).listen(PORT)
console.info(`Server started at http://localhost:${PORT}`)
const server = connect().use(sirv('./client/dist')).listen(port)
console.info(`\n\nServer started at`, colors.blue(`http://localhost:${port}`))
return server
}

Expand All @@ -110,18 +150,18 @@ async function bench() {
]

const browser = await launch({
// headless: false,
headless,
args,
})
const page = await browser.newPage()
await page.goto(`http://localhost:${PORT}/`, {
await page.goto(`http://localhost:${port}/`, {
waitUntil: 'networkidle0',
})

await forceGC()

const t = performance.now()
for (let i = 0; i < 50; i++) {
for (let i = 0; i < count; i++) {
await doAction('run')
await doAction('add')
await doAction('update')
Expand Down

0 comments on commit 11e43bb

Please sign in to comment.