Skip to content

Commit

Permalink
add tiny http
Browse files Browse the repository at this point in the history
  • Loading branch information
dancastillo committed Jul 30, 2023
1 parent 3487d94 commit 9af586b
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 2 deletions.
1 change: 0 additions & 1 deletion benchmark-results.json

This file was deleted.

9 changes: 9 additions & 0 deletions benchmarks/tinyhttp.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { App } from '@tinyhttp/app'

const app = new App()

app.get('/', (_, res) => {
res.send('Hello World!')
})

app.listen(3000)
2 changes: 2 additions & 0 deletions lib/autocannon.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import { writeFile as _writeFile, mkdir as _mkdir, access as _access } from 'fs'
import compare from 'autocannon-compare'
import { join } from 'path'
import { promisify } from 'util'
import { createRequire } from 'module'

const writeFile = promisify(_writeFile)
const mkdir = promisify(_mkdir)
const access = promisify(_access)
const require = createRequire(import.meta.url)

const resultsDirectory = join(process.cwd(), 'results')

Expand Down
10 changes: 9 additions & 1 deletion lib/bench.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env node
'use strict'

import { access } from 'node:fs/promises'
import { fork } from 'child_process'
import ora from 'ora'
import { join } from 'path'
Expand All @@ -12,7 +13,14 @@ const __dirname = fileURLToPath(new URL('.', import.meta.url))

const doBench = async (opts, handler) => {
const spinner = ora(`Started ${handler}`).start()
const forked = fork(join(__dirname, '..', 'benchmarks', handler + '.cjs'))
let forked
try {
await access(join(__dirname, '..', 'benchmarks', handler + '.cjs'))
forked = fork(join(__dirname, '..', 'benchmarks', handler + '.cjs'))
} catch {
forked = fork(join(__dirname, '..', 'benchmarks', handler + '.mjs'))
}

try {
spinner.color = 'magenta'
spinner.text = `Warming ${handler}`
Expand Down
1 change: 1 addition & 0 deletions lib/packages.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const packages = {
spirit: { extra: true },
'spirit-router': { extra: true, hasRouter: true },
'take-five': { hasRouter: true },
tinyhttp: { package: '@tinyhttp/app' },
'total.js': { hasRouter: true },
'trpc-router': { extra: true, hasRouter: true, package: '@trpc/server' },
vapr: { hasRouter: true },
Expand Down

0 comments on commit 9af586b

Please sign in to comment.