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].
Call tree
Section titled “Call tree”run_warehouse_tick ← #[factorio_rs::profile]├─ receive_shipments -> hash_sku -> mix64├─ pick_orders -> score_pick -> mix64└─ settle_ledger -> seal_chunk -> mix64pick_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.
Wall-clock benches
Section titled “Wall-clock benches”cd examples/benchmarkingfactorio-rs bench # default --profile releasefactorio-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.
Flamegraph
Section titled “Flamegraph”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();}- Launch with DAP:
factorio-rs dap --gui(or F5 in Zed). - Start a singleplayer game - the profiled function writes a
.cpuprofile. - Remap:
factorio-rs profile --skip-build - Open
~/.factorio/script-output/*.speedscope.jsonin speedscope.app.
See also: Benchmarking, Debugging, CLI.