DEV Community

eth shihao
eth shihao

Posted on

Benchmarking construction change order OH&P, bond, and tax in JavaScript

A $200 controls subcontract with two markup tiers becomes $247.40 after overhead, profit, and bond in this fixture. The paid base grows at each step.

Stage Base Applied rate Charge
Tier 2 $200.00 5% $10.00
Tier 1 $210.00 10% $21.00
Prime on subcontract $231.00 5% $11.55
Bond $242.55 2% $4.85

Both tier 2 and the prime on subcontract request 7.5% and hit their separate 5% caps. Tier 1 applies 10% to the tier 2 subtotal. Sales tax is disabled for this line. Saving the base and applied rate for each charge gives an estimator enough information to replay the quote.

Carry the rounding through the cascade

For $100.00 of taxable material with a 10% capped prime markup, direct cost is $100.00 and marked-up cost is $110.00. With 8% sales tax on direct cost and 2% bond, the order and basis change the result.

Cascade Tax Bond Total
Tax first, then bond on $118.00 $8.00 $2.36 $120.36
Bond first, then tax on $102.20 with attributable bond included $8.18 $2.20 $120.38

Each stage rounds half up to cents, with the rounded amount carried forward. The rounded bond for the controls line, for example, is $4.85 on a $242.55 base.

A deductive line starts with a positive cost magnitude and ends with a signed credit. In the direct-only policy, a $50.00 taxable equipment rental deduction credits $54.00 with 8% tax. There is zero markup and zero bond on the credit. The mirror policy reverses every component of the corresponding addition. Pick the policy and cascade that match the pricing terms.

Reconcile the contract and its schedule of values

The mixed fixture includes labor with 25% burden, materials, the controls subcontract, and the rental credit. Two lines share a schedule-of-values code, one baseline code is untouched, and the subcontract opens a new code. The four changes sum to $454.83, adjusting a $10,000.00 contract to $10,454.83. The SOV total follows the same adjustment.

Benchmark the complete pricing call

Run from the source checkout with Node.js 20 or later. The benchmark checks the individual lines, both cascade orders, and the rollup before timing. It then measures one mixed order, one bond-first material line, and a 64-line order with repeated tier paths and SOV codes. MIT source repository

node --input-type=module <<'JS'
import assert from 'node:assert/strict';
import { performance } from 'node:perf_hooks';
import { priceChangeOrder } from './src/index.js';

const lines = [
  { id: 'Crew', sovId: '03', kind: 'labor', amountCents: 10_000, burdenBps: 2500 },
  { id: 'Concrete', sovId: '03', kind: 'materials', amountCents: 10_000 },
  { id: 'Controls', sovId: '26', kind: 'subcontract', amountCents: 20_000, tier: 2 },
  { id: 'Lift', sovId: '01', kind: 'equipment', amountCents: 5000, direction: 'deduct' },
];
const mixed = {
  contractSumCents: 1_000_000,
  lines,
  markup: {
    primeSelf: { rateBps: 1500, capBps: 1000 },
    primeSub: { rateBps: 750, capBps: 500 },
    subcontractorTiers: [{ rateBps: 1000 }, { rateBps: 750, capBps: 500 }],
  },
  cascade: { order: 'tax-then-bond', taxBase: 'marked-up', taxRateBps: 800, bondRateBps: 200 },
  scheduleOfValues: [
    { id: '01', amountCents: 50_000 },
    { id: '03', amountCents: 500_000 },
    { id: '09', amountCents: 450_000 },
  ],
};
const bondFirst = {
  ...mixed, lines: [lines[1]],
  cascade: { ...mixed.cascade, order: 'bond-then-tax', taxBase: 'direct', taxIncludesBond: true },
};
const larger = {
  ...mixed,
  lines: Array.from({ length: 64 }, (_, index) => {
    const line = lines[index % lines.length];
    return { ...line, id: `${line.id}-${index}` };
  }),
};
const fixtures = [
  ['mixed / 4 lines', mixed, 45_483, 12_000],
  ['bond first / 1 line', bondFirst, 12_038, 12_000],
  ['mixed / 64 lines', larger, 727_728, 3000],
];

assert.deepEqual(priceChangeOrder(mixed).lines.map((line) => line.totalCents), [14_025, 12_118, 24_740, -5400]);
const taxFirst = { ...bondFirst, cascade: { ...bondFirst.cascade, order: 'tax-then-bond' } };
assert.equal(priceChangeOrder(taxFirst).totals.changeCents, 12_036);
const mirror = { ...bondFirst, direction: 'deduct', creditPolicy: 'mirror' };
assert.equal(priceChangeOrder(mirror).totals.changeCents, -12_038);

const measurements = [];
for (const [fixture, input, expected, iterations] of fixtures) {
  const result = priceChangeOrder(input);
  assert.equal(result.totals.changeCents, expected);
  assert.equal(result.adjustedContractSumCents, input.contractSumCents + expected);
  assert.equal(result.sov.reduce((total, row) => total + row.changeCents, 0), expected);
  assert.equal(result.sov.reduce((total, row) => total + row.adjustedCents, 0), result.adjustedContractSumCents);

  for (let i = 0; i < 600; i++) priceChangeOrder(input);
  const samples = [];
  for (let sample = 0; sample < 5; sample++) {
    let checksum = 0;
    const start = performance.now();
    for (let i = 0; i < iterations; i++) checksum += priceChangeOrder(input).totals.changeCents;
    samples.push(performance.now() - start);
    assert.equal(checksum, expected * iterations);
  }

  const median = samples.sort((a, b) => a - b)[2];
  measurements.push({ fixture, iterations, medianMs: Number(median.toFixed(2)), callsPerSecond: Math.round(1000 * iterations / median) });
}
console.log(process.version, process.platform, process.arch);
console.table(measurements);
JS
Enter fullscreen mode Exit fullscreen mode

One run on arm64 macOS with Node.js v24.14.1 produced these medians over five samples.

Fixture Calls per sample Median Calls per second
Mixed order, 4 lines 12,000 34.58 ms 347,058
Bond first, 1 line 12,000 21.63 ms 554,757
Mixed order, 64 lines 3,000 75.26 ms 39,862

The pricing call processes each line once and visits each applicable markup tier once. It groups already-rounded line totals by SOV code. That grouping step preserves the exact cents reported on the detail lines.

Change the credit policy or cascade in the GitHub Pages demo. Related tools include the Change Order Calculator and Equipment Rental Calculator.

Top comments (0)