A synthetic but realistic benchmark designed to exercise jsPerf's browser runner, Deep Analysis, Node/Deno/Bun runtime comparison, V8 JIT artifacts, and CPU profile viewer.
The two cases compare a stable monomorphic order-scoring path against a polymorphic normalization path with mixed object shapes and Set/tag handling. Setup owns data generation so measured snippets focus on hot-path behavior rather than fixture construction.
const tenants = Array.from({ length: 12 }, (_, tenantId) => ({
tenantId,
riskFloor: (tenantId % 5) + 1,
}))
const orders = Array.from({ length: 256 }, (_, i) => ({
tenantId: i % tenants.length,
sku: 'sku-' + (i % 64),
quantity: (i % 7) + 1,
priceCents: 199 + ((i * 17) % 2900),
tags: i % 11 === 0 ? ['priority', 'cold-start'] : ['standard'],
}))
const routingBySku = new Map(orders.map((order, index) => [order.sku, index % 8]))
const weights = new Float64Array([1.13, 0.97, 1.41, 0.88, 1.05, 1.22, 0.79, 1.34])
const fallbackTags = new Set(['standard'])
const mixedOrders = orders.map((order, index) => index % 3 === 0
? { ...order, coupon: 'SAVE' + (index % 5), tags: new Set(order.tags) }
: index % 3 === 1
? {
tenant: order.tenantId,
sku: order.sku,
quantity: String(order.quantity),
priceCents: order.priceCents,
tags: order.tags,
}
: Object.create(null, {
sku: { value: order.sku, enumerable: true },
quantity: { value: order.quantity, enumerable: true },
priceCents: { value: order.priceCents, enumerable: true },
tags: { value: null, enumerable: true },
}))
let checksum = 0
function normalizePolymorphic(order) {
const quantity = typeof order.quantity === 'string' ? Number(order.quantity) : order.quantity
const tags = order.tags instanceof Set ? order.tags : new Set(order.tags || fallbackTags)
const route = routingBySku.get(order.sku) ?? 0
return ((quantity || 0) * (order.priceCents || 0) * weights[route]) + (tags.has('priority') ? 17 : 3)
}Initializing...
| Test Case | Ops/sec | |
|---|---|---|
| Indexed order scoring (monomorphic Map + typed array) | | ready |
| Polymorphic order normalization (mixed shapes + Set tags) | | ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.