To add a new benchmark, follow these three steps:
1. Define the benchmark function
Create a function or method named time_*. You have two patterns:
Pattern A: Class-based (using BenchmarkClass)
Use this if you need a shared setup method. Inherit from BenchmarkClass from benchmarks.bench_utils.
Pattern B: Standalone function
Use this for simple, module-scope functions. These do not inherit from BenchmarkClass.
Note on @safe_to_repeat: If the benchmark call is independent and does not alter state that would affect subsequent runs (e.g., it only reads immutable inputs), decorate it with @safe_to_repeat from benchmarks.bench_utils.
2. Define workloads (if necessary)
If your benchmark requires specific xDSL operations or workloads, add them to benchmarks/workloads.py as a new class method on WorkloadBuilder.
3. Register for local profiling
Associate the benchmark with a name in the profile call at the bottom of your file using BenchmarkFunction from bench_utils.
import importlib
import xdsl.dialects.newdialect
from benchmarks.bench_utils import BenchmarkClass, safe_to_repeat
class ImportDialects(BenchmarkClass):
@safe_to_repeat
def time_newdialect_load(self) -> None:
"""Time loading the `newdialect` dialect.""
importlib.reload(xdsl.dialects.newdialect)
# To register for local profiling:
from bench_utils import BenchmarkFunction, profile
profile(
{
"Dialects.newdialect_load": BenchmarkFunction(time_newdialect_load),
}
)