Order book benchmarks

OrderBook keeps each side in a vector sorted best first, so a read is an index or a binary search and a write moves the levels below it. These charts are that trade: what each operation costs against the depth of one side, from a top-of-book feed at 8 levels out to 512, further than an exchange publishes and far enough for the memmove to separate from the search.

cpu 12th Gen Intel(R) Core(TM) i7-12700H arch x86_64 rustc rustc 1.98.0 (88d9e12ae 2026-08-18) commit 623f30c (modified) measured 2026-09-05 15:23 UTC

Against depth

One chart per operation, each scaled to its own slowest point, with depth on a log axis because it quadruples between samples. A flat line is an operation that does not care how deep the book is. Accesses are scattered rather than sequential, so the cache miss a real feed produces is in the number.

best

Best price on one side

01234ns832128512Levels on one sideDec at 8: 2.23 nsDec at 32: 2.23 nsDec at 128: 3.37 nsDec at 512: 3.39 ns

top

Best bid and ask, mid and spread

01234ns832128512Levels on one sideDec at 8: 3.91 nsDec at 32: 3.91 nsDec at 128: 3.91 nsDec at 512: 3.91 ns

nth

Reach a level by rank

0123ns832128512Levels on one sideDec at 8: 1.46 nsDec at 32: 1.51 nsDec at 128: 2.20 nsDec at 512: 1.46 ns

find

Reach a level by price

051015ns832128512Levels on one sideDec at 8: 6.72 nsDec at 32: 7.71 nsDec at 128: 9.34 nsDec at 512: 11.2 ns

update

Replace the amount at a price held

051015ns832128512Levels on one sideDec at 8: 7.73 nsDec at 32: 9.64 nsDec at 128: 11.5 nsDec at 512: 13.1 ns

apply_diff

Apply a batch of level updates

051015ns832128512Levels on one sideDec at 8: 7.23 nsDec at 32: 8.81 nsDec at 128: 10.1 nsDec at 512: 11.9 ns

insert

Add a price the book does not hold

050100150ns832128512Levels on one sideDec at 8: 12.4 nsDec at 32: 24.2 nsDec at 128: 51.8 nsDec at 512: 137 ns

remove

Take a level out

050100150200ns832128512Levels on one sideDec at 8: 9.50 nsDec at 32: 21.6 nsDec at 128: 53.7 nsDec at 512: 157 ns

churn

Insert and evict on a capped book

050100150200ns832128512Levels on one sideDec at 8: 18.0 nsDec at 32: 28.3 nsDec at 128: 62.9 nsDec at 512: 195 ns

stats

Total size and notional over a side

0100020003000ns832128512Levels on one sideDec at 8: 48.5 nsDec at 32: 221 nsDec at 128: 823 nsDec at 512: 2,064 ns

Summary

The same numbers as one table, with the ends of each sweep divided.

Nanoseconds per operation against the depth of one side, median of criterion's samples. The last column is the cost at 512 levels over the cost at 8; ★ marks the operations that stay flat.
operation832128512512 / 8
best2.232.233.373.391.5×
top3.913.913.913.911.0×
nth1.461.512.201.461.0×
find6.727.719.3411.221.7×
update7.739.6411.5013.121.7×
apply_diff7.238.8110.0611.941.7×
insert12.4524.2151.78136.8211.0×
remove9.5021.6053.70157.0616.5×
churn18.0528.3562.91194.6110.8×
stats48.50221.38823.202063.8242.6×