Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions internal-packages/benchmark-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"private": true,
"type": "module",
"exports": {
"./run-build": "./src/run-build.ts",
"./seeded-random": "./src/seeded-random.ts"
},
"devDependencies": {
Expand Down
33 changes: 33 additions & 0 deletions internal-packages/benchmark-utils/src/run-build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { execSync } from 'node:child_process'
import { Buffer } from 'node:buffer'
import { delimiter, resolve } from 'node:path'

function asString(value: unknown): string {
if (typeof value === 'string') return value
if (Buffer.isBuffer(value)) return value.toString('utf8')
return ''
}

export function runBuild(configName: string, baseDir: string): void {
const localBin = resolve(baseDir, 'node_modules/.bin')
const env = {
...process.env,
PATH: `${localBin}${delimiter}${process.env.PATH ?? ''}`,
}
try {
execSync(`rolldown -c configs/${configName}.ts`, {
cwd: baseDir,
stdio: 'pipe',
env,
})
} catch (err) {
const isObject = typeof err === 'object' && err !== null
const status = isObject && 'status' in err && typeof err.status === 'number' ? err.status : null
const stdout = asString(isObject && 'stdout' in err ? err.stdout : undefined)
const stderr = asString(isObject && 'stderr' in err ? err.stderr : undefined)
throw new Error(
`build:${configName} failed (exit ${status ?? 'unknown'}):\n${stdout}${stderr}`,
{ cause: err },
)
}
}
22 changes: 10 additions & 12 deletions packages/emotion/benchmark/bench/emotion.bench.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import { bench, describe } from 'vitest'
import { execSync } from 'node:child_process'
import { existsSync, rmSync } from 'node:fs'
import { existsSync, readdirSync, rmSync } from 'node:fs'
import { resolve } from 'node:path'
import { runBuild } from '@rolldown/benchmark-utils/run-build'

const baseDir = resolve(import.meta.dirname, '..')
const distBase = resolve(baseDir, 'dist')
const componentsDir = resolve(baseDir, 'shared-app/src/components')
const expectedComponents = 100

if (!existsSync(componentsDir)) {
const currentComponents = existsSync(componentsDir)
? readdirSync(componentsDir).filter((f) => f.endsWith('.tsx')).length
: 0
if (currentComponents !== expectedComponents) {
execSync('pnpm generate', { cwd: baseDir, stdio: 'inherit' })
}

Expand All @@ -18,34 +23,27 @@ function cleanDist(name: string) {
}
}

function runBuild(name: string) {
execSync(`rolldown -c configs/${name}.ts`, {
cwd: baseDir,
stdio: 'pipe',
})
}

describe('Emotion Benchmark', () => {
bench(
'@rolldown/plugin-emotion',
() => {
runBuild('custom')
runBuild('custom', baseDir)
},
{ teardown: () => cleanDist('custom') },
)

bench(
'@rolldown/plugin-babel',
() => {
runBuild('babel')
runBuild('babel', baseDir)
},
{ teardown: () => cleanDist('babel') },
)

bench(
'@rollup/plugin-swc',
() => {
runBuild('swc')
runBuild('swc', baseDir)
},
{ teardown: () => cleanDist('swc') },
)
Expand Down
21 changes: 21 additions & 0 deletions packages/emotion/benchmark/bench/emotion.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { describe, test } from 'vitest'
import { execSync } from 'node:child_process'
import { resolve } from 'node:path'
import { runBuild } from '@rolldown/benchmark-utils/run-build'

const baseDir = resolve(import.meta.dirname, '..')

execSync('pnpm generate -- --total=10 --silent', {
cwd: baseDir,
stdio: 'inherit',
})

describe('Emotion build', () => {
test.for(['custom', 'babel', 'swc'] as const)(
'build:%s exits with code 0',
{ timeout: 30_000 },
(name) => {
runBuild(name, baseDir)
},
)
})
12 changes: 8 additions & 4 deletions packages/emotion/benchmark/scripts/generate-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,9 @@ function main() {
mkdirSync(componentsDir, { recursive: true })

const components: Array<{ type: ComponentType; index: number }> = []
const TOTAL = 100
const totalArg = process.argv.find((a) => a.startsWith('--total='))
const TOTAL = totalArg ? Number.parseInt(totalArg.slice('--total='.length), 10) : 100
const silent = process.argv.includes('--silent')
const perType = Math.floor(TOTAL / COMPONENT_TYPES.length)
const remainder = TOTAL % COMPONENT_TYPES.length

Expand All @@ -293,9 +295,11 @@ function main() {
.join('\n')
writeFileSync(join(componentsDir, 'index.ts'), exports + '\n')

console.log(`Generated ${components.length} components in ${componentsDir}`)
for (const type of COMPONENT_TYPES) {
console.log(` ${type}: ${components.filter((c) => c.type === type).length}`)
if (!silent) {
console.log(`Generated ${components.length} components in ${componentsDir}`)
for (const type of COMPONENT_TYPES) {
console.log(` ${type}: ${components.filter((c) => c.type === type).length}`)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import { bench, describe } from 'vitest'
import { execSync } from 'node:child_process'
import { existsSync, rmSync } from 'node:fs'
import { existsSync, readdirSync, rmSync } from 'node:fs'
import { resolve } from 'node:path'
import { runBuild } from '@rolldown/benchmark-utils/run-build'

const baseDir = resolve(import.meta.dirname, '..')
const distBase = resolve(baseDir, 'dist')
const componentsDir = resolve(baseDir, 'shared-app/src/components')
const expectedComponents = 100

if (!existsSync(componentsDir)) {
const currentComponents = existsSync(componentsDir)
? readdirSync(componentsDir).filter((f) => f.endsWith('.tsx')).length
: 0
if (currentComponents !== expectedComponents) {
execSync('pnpm generate', { cwd: baseDir, stdio: 'inherit' })
}

Expand All @@ -18,34 +23,27 @@ function cleanDist(name: string) {
}
}

function runBuild(name: string) {
execSync(`rolldown -c configs/${name}.ts`, {
cwd: baseDir,
stdio: 'pipe',
})
}

describe('JSX Remove Attributes Benchmark', () => {
bench(
'@rolldown/plugin-jsx-remove-attributes',
() => {
runBuild('custom')
runBuild('custom', baseDir)
},
{ teardown: () => cleanDist('custom') },
)

bench(
'@rolldown/plugin-babel',
() => {
runBuild('babel')
runBuild('babel', baseDir)
},
{ teardown: () => cleanDist('babel') },
)

bench(
'@rollup/plugin-swc',
() => {
runBuild('swc')
runBuild('swc', baseDir)
},
{ teardown: () => cleanDist('swc') },
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { describe, test } from 'vitest'
import { execSync } from 'node:child_process'
import { resolve } from 'node:path'
import { runBuild } from '@rolldown/benchmark-utils/run-build'

const baseDir = resolve(import.meta.dirname, '..')

execSync('pnpm generate -- --total=10 --silent', {
cwd: baseDir,
stdio: 'inherit',
})

describe('JSX Remove Attributes build', () => {
test.for(['custom', 'babel', 'swc'] as const)(
'build:%s exits with code 0',
{ timeout: 30_000 },
(name) => {
runBuild(name, baseDir)
},
)
})
12 changes: 8 additions & 4 deletions packages/jsx-remove-attributes/benchmark/scripts/generate-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,9 @@ function main() {
mkdirSync(componentsDir, { recursive: true })

const components: Array<{ type: ComponentType; index: number }> = []
const TOTAL = 100
const totalArg = process.argv.find((a) => a.startsWith('--total='))
const TOTAL = totalArg ? Number.parseInt(totalArg.slice('--total='.length), 10) : 100
const silent = process.argv.includes('--silent')
const perType = Math.floor(TOTAL / COMPONENT_TYPES.length)
const remainder = TOTAL % COMPONENT_TYPES.length

Expand All @@ -203,9 +205,11 @@ function main() {
.join('\n')
writeFileSync(join(componentsDir, 'index.ts'), exports + '\n')

console.log(`Generated ${components.length} components in ${componentsDir}`)
for (const type of COMPONENT_TYPES) {
console.log(` ${type}: ${components.filter((c) => c.type === type).length}`)
if (!silent) {
console.log(`Generated ${components.length} components in ${componentsDir}`)
for (const type of COMPONENT_TYPES) {
console.log(` ${type}: ${components.filter((c) => c.type === type).length}`)
}
}
}

Expand Down
22 changes: 10 additions & 12 deletions packages/styled-jsx/benchmark/bench/styled-jsx.bench.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import { bench, describe } from 'vitest'
import { execSync } from 'node:child_process'
import { existsSync, rmSync } from 'node:fs'
import { existsSync, readdirSync, rmSync } from 'node:fs'
import { resolve } from 'node:path'
import { runBuild } from '@rolldown/benchmark-utils/run-build'

const baseDir = resolve(import.meta.dirname, '..')
const distBase = resolve(baseDir, 'dist')
const componentsDir = resolve(baseDir, 'shared-app/src/components')
const expectedComponents = 100

if (!existsSync(componentsDir)) {
const currentComponents = existsSync(componentsDir)
? readdirSync(componentsDir).filter((f) => f.endsWith('.tsx')).length
: 0
if (currentComponents !== expectedComponents) {
execSync('pnpm generate', { cwd: baseDir, stdio: 'inherit' })
}

Expand All @@ -18,34 +23,27 @@ function cleanDist(name: string) {
}
}

function runBuild(name: string) {
execSync(`rolldown -c configs/${name}.ts`, {
cwd: baseDir,
stdio: 'pipe',
})
}

describe('Styled JSX Benchmark', () => {
bench(
'@rolldown/plugin-styled-jsx',
() => {
runBuild('custom')
runBuild('custom', baseDir)
},
{ teardown: () => cleanDist('custom') },
)

bench(
'@rolldown/plugin-babel',
() => {
runBuild('babel')
runBuild('babel', baseDir)
},
{ teardown: () => cleanDist('babel') },
)

bench(
'@rollup/plugin-swc',
() => {
runBuild('swc')
runBuild('swc', baseDir)
},
{ teardown: () => cleanDist('swc') },
)
Expand Down
21 changes: 21 additions & 0 deletions packages/styled-jsx/benchmark/bench/styled-jsx.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { describe, test } from 'vitest'
import { execSync } from 'node:child_process'
import { resolve } from 'node:path'
import { runBuild } from '@rolldown/benchmark-utils/run-build'

const baseDir = resolve(import.meta.dirname, '..')

execSync('pnpm generate -- --total=10 --silent', {
cwd: baseDir,
stdio: 'inherit',
})

describe('Styled JSX build', () => {
test.for(['custom', 'babel', 'swc'] as const)(
'build:%s exits with code 0',
{ timeout: 30_000 },
(name) => {
runBuild(name, baseDir)
},
)
})
12 changes: 8 additions & 4 deletions packages/styled-jsx/benchmark/scripts/generate-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,9 @@ function main() {
mkdirSync(componentsDir, { recursive: true })

const components: Array<{ type: ComponentType; index: number }> = []
const TOTAL = 100
const totalArg = process.argv.find((a) => a.startsWith('--total='))
const TOTAL = totalArg ? Number.parseInt(totalArg.slice('--total='.length), 10) : 100
const silent = process.argv.includes('--silent')
const perType = Math.floor(TOTAL / COMPONENT_TYPES.length)
const remainder = TOTAL % COMPONENT_TYPES.length

Expand All @@ -294,9 +296,11 @@ function main() {
.join('\n')
writeFileSync(join(componentsDir, 'index.ts'), exports + '\n')

console.log(`Generated ${components.length} components in ${componentsDir}`)
for (const type of COMPONENT_TYPES) {
console.log(` ${type}: ${components.filter((c) => c.type === type).length}`)
if (!silent) {
console.log(`Generated ${components.length} components in ${componentsDir}`)
for (const type of COMPONENT_TYPES) {
console.log(` ${type}: ${components.filter((c) => c.type === type).length}`)
}
}
}

Expand Down
Loading
Loading