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
4 changes: 2 additions & 2 deletions .github/workflows/codspeed.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CodSpeed Benchmarks
name: CodSpeed

on:
push:
Expand All @@ -25,5 +25,5 @@ jobs:

- uses: CodSpeedHQ/action@v4
with:
mode: walltime
mode: simulation
run: pnpm run bench
Original file line number Diff line number Diff line change
@@ -1,34 +1,14 @@
import type { AddressInfo } from 'node:net'
import type { ClientServer } from './client-server'
import { serve } from '@hono/node-server'
import { toFetchBody, toFetchHeaders, toFetchResponse, toStandardLazyRequest, toStandardLazyResponse } from '@standardserver/fetch'

/**
* Real Hono/node-server + fetch adapter round-trip.
*/
export function createHonoFetchClientServer(): ClientServer {
export function createFetchClientServer(): ClientServer {
const clientServer: ClientServer = {
handler: async () => ({ status: 404, body: 'Not Found', headers: {} }),
request: async () => {
throw new Error('client-server not ready')
},
}

const server = serve({
fetch: async (request: Request) => {
const standardRequest = toStandardLazyRequest(request)
const standardResponse = await clientServer.handler(standardRequest)
return toFetchResponse(standardResponse)
},
port: 0,
})

afterAll(() => {
server.close()
})

const addressInfo = server.address() as AddressInfo

clientServer.request = async (standardRequest) => {
const [body, standardHeaders] = toFetchBody(standardRequest.body, standardRequest.headers)

Expand All @@ -43,9 +23,15 @@ export function createHonoFetchClientServer(): ClientServer {
init.duplex = 'half'
}

const response = await fetch(`http://localhost:${addressInfo.port}${standardRequest.url}`, init)

return toStandardLazyResponse(response)
return toStandardLazyResponse(
toFetchResponse(
await clientServer.handler(
toStandardLazyRequest(
new Request(`http://localhost:${standardRequest.url}`, init),
),
),
),
)
}

return clientServer
Expand Down
108 changes: 0 additions & 108 deletions benches/__shared__/client-server.node-ws.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ import * as http from 'node:http'
import { toFetchBody, toFetchHeaders, toStandardLazyResponse } from '@standardserver/fetch'
import { sendStandardResponse, toStandardLazyRequest } from '@standardserver/node'

/**
* Real Node.js `http` server + `fetch` client (node adapter on the server side).
*/
export function createNodeHttpClientServer(): ClientServer {
export function createNodeClientServer(): ClientServer {
const clientServer: ClientServer = {
handler: async () => ({ status: 404, body: 'Not Found', headers: {} }),
request: async () => {
Expand Down
37 changes: 37 additions & 0 deletions benches/__shared__/client-server.peer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import type { ClientServer } from './client-server'
import { ClientPeer, decodePeerMessage, encodePeerMessage, isClientPeerSendMessage, isServerPeerSendMessage, ServerPeer } from '@standardserver/peer'

export function createPeerClientServer(): ClientServer {
let clientPeer: ClientPeer

const clientServer: ClientServer = {
handler: async () => ({ status: 404, body: 'Not Found', headers: {} }),
request: async (standardRequest) => {
return clientPeer.request(standardRequest)
},
}

const serverPeer = new ServerPeer(async (message) => {
const encoded = await encodePeerMessage(message)
const decoded = decodePeerMessage(encoded)

if (!decoded.matched || !isServerPeerSendMessage(decoded.message)) {
return
}

clientPeer.message(decoded.message)
})

clientPeer = new ClientPeer(async (message) => {
const encoded = await encodePeerMessage(message)
const decoded = decodePeerMessage(encoded)

if (!decoded.matched || !isClientPeerSendMessage(decoded.message)) {
throw new Error('not found')
}

serverPeer.message(decoded.message, clientServer.handler)
})

return clientServer
}
Loading
Loading