Skip to content

benchmarking

Path: examples/benchmarking.

A small control mod with a nested call tree (warehouse tick) used for both #[factorio_rs::bench] wall-clock timings and DAP flamegraphs via #[factorio_rs::profile].

run_warehouse_tick ← #[factorio_rs::profile]
├─ receive_shipments -> hash_sku -> mix64
├─ pick_orders -> score_pick -> mix64
└─ settle_ledger -> seal_chunk -> mix64

pick_orders / score_pick do the most work (and call hash_sku per order), so Speedscope should show a wide band there with mix64 underneath - not one anonymous loop.

Terminal window
cd examples/benchmarking
factorio-rs bench # default --profile release
factorio-rs bench warehouse_tick # name filter (substring)
Bench What it times
warehouse_tick full nested tick
pick_orders_only pick only (no settle)

Requires a Factorio binary (FACTORIO_PATH). Details: Benchmarking.

Mark the hot function (already done in this example):

use factorio_rs::prelude::*;
#[profile]
fn run_warehouse_tick() {
// ...
}
#[event(OnSingleplayerInit)]
pub fn on_singleplayer_init() {
run_warehouse_tick();
}
  1. Launch with DAP: factorio-rs dap --gui (or F5 in Zed).
  2. Start a singleplayer game - the profiled function writes a .cpuprofile.
  3. Remap: factorio-rs profile --skip-build
  4. Open ~/.factorio/script-output/*.speedscope.json in speedscope.app.

See also: Benchmarking, Debugging, CLI.