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
37 changes: 0 additions & 37 deletions benches/__shared__/payloads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ function createUnit(i: number) {
}
}

const SIZE_1KB = 1024
const SIZE_10KB = 10 * SIZE_1KB
const SIZE_100KB = 100 * SIZE_1KB
const SIZE_5MB = 5 * 1024 * 1024

export const PAYLOAD_1KB = createUnit(0)
Expand All @@ -60,25 +57,6 @@ export const EVENTS_10KB = Array.from({ length: 10 }).fill(PAYLOAD_1KB)
export const EVENTS_100KB = Array.from({ length: 50 }).fill([PAYLOAD_1KB, PAYLOAD_1KB])
export const EVENTS_5MB = Array.from({ length: 1000 }).fill([PAYLOAD_1KB, PAYLOAD_1KB, PAYLOAD_1KB, PAYLOAD_1KB, PAYLOAD_1KB])

function splitBytes(size: number, parts: number): Uint8Array<ArrayBuffer>[] {
const buf = new Uint8Array(size)
const base = Math.floor(size / parts)
let rem = size - base * parts
const out: Uint8Array<ArrayBuffer>[] = []
let off = 0
for (let i = 0; i < parts; i++) {
const n = base + (rem-- > 0 ? 1 : 0)
out.push(buf.subarray(off, off + n))
off += n
}
return out
}

export const BYTES_1KB = splitBytes(SIZE_1KB, 1)
export const BYTES_10KB = splitBytes(SIZE_10KB, 10)
export const BYTES_100KB = splitBytes(SIZE_100KB, 50)
export const BYTES_5MB = splitBytes(SIZE_5MB, 1000)

/** Fresh async generator over prebuilt event parts (one-shot per call). */
export function asSyncIteratorObject(parts: readonly unknown[]): AsyncGenerator<unknown, void, undefined> {
return (async function* () {
Expand All @@ -88,21 +66,6 @@ export function asSyncIteratorObject(parts: readonly unknown[]): AsyncGenerator<
}())
}

/** Fresh ReadableStream over prebuilt octet chunks (one-shot per call). */
export function asReadableStream(parts: readonly Uint8Array<ArrayBuffer>[]): ReadableStream<Uint8Array<ArrayBuffer>> {
let i = 0
return new ReadableStream({
pull(controller) {
if (i >= parts.length) {
controller.close()
}
else {
controller.enqueue(parts[i++]!)
}
},
})
}

export async function drainBody(body: unknown): Promise<void> {
if (body === undefined || body === null) {
return
Expand Down
8 changes: 1 addition & 7 deletions benches/openapi-link-handler.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { OpenAPIHandlerCodec, OpenAPILinkCodec } from '@orpc/openapi/standard'
import { os, type } from '@orpc/server'
import { StandardHandler } from '@orpc/server/standard'
import { bench } from 'vitest'
import { asReadableStream, asSyncIteratorObject, BYTES_10KB, drainBody, EVENTS_10KB, handlers, PAYLOAD_10KB } from './__shared__/payloads'
import { asSyncIteratorObject, drainBody, EVENTS_10KB, handlers, PAYLOAD_10KB } from './__shared__/payloads'

const serializer = new OpenAPISerializer({ handlers })

Expand Down Expand Up @@ -46,10 +46,4 @@ describe('openapi link + handler', () => {
await client.ping(asSyncIteratorObject(EVENTS_10KB)),
)
})

bench('octet stream', async () => {
await drainBody(
await client.ping(asReadableStream(BYTES_10KB)),
)
})
})
8 changes: 1 addition & 7 deletions benches/rpc-link-handler.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { RPCLinkCodec, StandardLink } from '@orpc/client/standard'
import { os, type } from '@orpc/server'
import { RPCHandlerCodec, StandardHandler } from '@orpc/server/standard'
import { bench } from 'vitest'
import { asReadableStream, asSyncIteratorObject, BYTES_10KB, drainBody, EVENTS_10KB, handlers, PAYLOAD_10KB } from './__shared__/payloads'
import { asSyncIteratorObject, drainBody, EVENTS_10KB, handlers, PAYLOAD_10KB } from './__shared__/payloads'

const serializer = new RPCSerializer({ handlers })

Expand Down Expand Up @@ -44,10 +44,4 @@ describe('rpc link + handler', () => {
await client.ping(asSyncIteratorObject(EVENTS_10KB)),
)
})

bench('octet stream', async () => {
await drainBody(
await client.ping(asReadableStream(BYTES_10KB)),
)
})
})
Loading