Skip to content
Open
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
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,33 @@ bun run src/index.ts
```

This project was created using `bun init` in bun v1.0.0. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime.

## Drill benchmarks

``` bash
bash ./utils/script.sh <target> <tag> <json>
```

### Dependencies
- rust
- bun
- node (npm)
- drill
- gnuplot

### Targets
- bun
- bun-elysia
- bun-express
- node-express
- rust-rocket

### Tags
- hello
- json-copy
- json-struct
- json-walk

### json
- small
- medium
169 changes: 169 additions & 0 deletions bun-elysia/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore

# Logs

logs
_.log
npm-debug.log_
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)

report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json

# Runtime data

pids
_.pid
_.seed
\*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover

lib-cov

# Coverage directory used by tools like istanbul

coverage
\*.lcov

# nyc test coverage

.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)

.grunt

# Bower dependency directory (https://bower.io/)

bower_components

# node-waf configuration

.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)

build/Release

# Dependency directories

node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)

web_modules/

# TypeScript cache

\*.tsbuildinfo

# Optional npm cache directory

.npm

# Optional eslint cache

.eslintcache

# Optional stylelint cache

.stylelintcache

# Microbundle cache

.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history

.node_repl_history

# Output of 'npm pack'

\*.tgz

# Yarn Integrity file

.yarn-integrity

# dotenv environment variable files

.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)

.cache
.parcel-cache

# Next.js build output

.next
out

# Nuxt.js build / generate output

.nuxt
dist

# Gatsby files

.cache/

# Comment in the public line in if your project uses Gatsby and not Next.js

# https://nextjs.org/blog/next-9-1#public-directory-support

# public

# vuepress build output

.vuepress/dist

# vuepress v2.x temp and cache directory

.temp
.cache

# Docusaurus cache and generated files

.docusaurus

# Serverless directories

.serverless/

# FuseBox cache

.fusebox/

# DynamoDB Local files

.dynamodb/

# TernJS port file

.tern-port

# Stores VSCode versions used for testing VSCode extensions

.vscode-test

# yarn v2

.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.\*
15 changes: 15 additions & 0 deletions bun-elysia/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# bun-elysia

To install dependencies:

```bash
bun install
```

To run:

```bash
bun run src/index.ts
```

This project was created using `bun init` in bun v1.0.0. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime.
Binary file added bun-elysia/bun.lockb
Binary file not shown.
20 changes: 20 additions & 0 deletions bun-elysia/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "bun-elysia",
"version": "0.0.1",
"module": "src/index.ts",
"type": "module",
"scripts": {
"dev": "bun --watch src/index.ts",
"build": "bun build --target=bun --outdir=dist src/index.ts",
"start": "bun dist/index.js"
},
"devDependencies": {
"bun-types": "latest"
},
"peerDependencies": {
"typescript": "^5.0.0"
},
"dependencies": {
"elysia": "^0.6.23"
}
}
20 changes: 20 additions & 0 deletions bun-elysia/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Elysia } from 'elysia'

import helloRouter from './routes/hello'
import jsonCopyRouter from './routes/json_copy'
import jsonStructRouter from './routes/json_struct'
import jsonWalkRouter from './routes/json_walk'

const port = 8000
const app = new Elysia()

app.use(helloRouter)
app.use(jsonCopyRouter)
app.use(jsonStructRouter)
app.use(jsonWalkRouter)

app.get('*', (): Response => {
return new Response("Not found", { status: 404, headers: { "Content-Type": "text/plain" } })
}).listen(port)

console.log(`🦊 Elysia is running at ${app.server?.hostname}:${app.server?.port}`)
9 changes: 9 additions & 0 deletions bun-elysia/src/routes/hello.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Elysia } from 'elysia'

const router = new Elysia()

router.get('/hello', (): Response => {
return new Response("Hello World", { status: 200, headers: { "Content-Type": "text/plain" } })
})

export default router
11 changes: 11 additions & 0 deletions bun-elysia/src/routes/json_copy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Elysia } from 'elysia'

const router = new Elysia()

router.post('/json/copy', async ({request}) => {
const copy = JSON.stringify(JSON.parse(JSON.stringify(await request.json())))

return new Response(copy, { status: 200, headers: { "Content-Type": "application/json" } })
})

export default router
9 changes: 9 additions & 0 deletions bun-elysia/src/routes/json_struct.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Elysia } from 'elysia'

const router = new Elysia()

router.post('/json/struct', async ({request}) => {
return new Response(JSON.stringify(await request.json()), { status: 200, headers: { "Content-Type": "application/json" } })
})

export default router
34 changes: 34 additions & 0 deletions bun-elysia/src/routes/json_walk.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Elysia } from 'elysia'

const router = new Elysia()

router.post('/json/walk', async ({request}) => {
const walk = walkBody(await request.json())

return new Response(JSON.stringify(walk), { status: 200, headers: { "Content-Type": "application/json" } })
})

function walkBody(body: any): any {
if (Array.isArray(body)) {
for (let key = 0; key < body.length; key++) {
const value = body[key]
if (typeof value === "object") {
walkBody(value)
} else if (typeof value === "number") {
body[key] = value + 1
}
}
} else if (typeof body === "object") {
for (const [key, value] of Object.entries(body)) {
if (typeof value === "object") {
walkBody(value)
} else if (typeof value === "number") {
body[key] = value + 1
}
}
}

return body
}

export default router
22 changes: 22 additions & 0 deletions bun-elysia/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"compilerOptions": {
"lib": ["ESNext"],
"module": "esnext",
"target": "esnext",
"moduleResolution": "bundler",
"moduleDetection": "force",
"allowImportingTsExtensions": true,
"noEmit": true,
"composite": true,
"strict": true,
"downlevelIteration": true,
"skipLibCheck": true,
"jsx": "preserve",
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"allowJs": true,
"types": [
"bun-types" // add Bun global
]
}
}
Loading