Synthetic Commerce JIT and CPU Profile Showcase

Benchmark published by jsperf system on

Description

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.

Setup

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)
}

Test Runner

Initializing...

Testing in
Test CaseOps/sec
Indexed order scoring (monomorphic Map + typed array)
let total = 0
for (let i = 0; i < orders.length; i++) {
  const order = orders[i]
  const route = routingBySku.get(order.sku) ?? 0
  total += ((order.quantity * order.priceCents * weights[route]) + route) | 0
}
checksum = (checksum ^ total) | 0
return checksum
ready
Polymorphic order normalization (mixed shapes + Set tags)
let total = 0
for (let i = 0; i < mixedOrders.length; i++) {
  const order = mixedOrders[i]
  const tags = order.tags instanceof Set ? order.tags : fallbackTags
  total += normalizePolymorphic(order) + (tags.has('priority') ? 1 : 0)
}
checksum = (checksum + total) | 0
return checksum
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.

Revision 1
publishedby jsperf systemon