synthesizer.utils.operation_timers

Dict-like interface to C++ accumulated operation timings.

Classes

class synthesizer.utils.operation_timers.OperationTimers[source]

Dictionary-like interface to accumulated operation timings.

This class provides access to timing data accumulated by C++ and Python toc() calls. It behaves like a dictionary where keys are operation names and values are tuples of (cumulative_time, call_count, source).

The underlying timing data is stored in C++ using atomic operations for thread-safe accumulation. This class simply provides a Pythonic interface to access that data.

Example

>>> timers = OperationTimers()
>>> timers.reset()
>>> # ... run some operations that call tic()/toc() ...
>>> print(timers.keys())
['Finding particle grid indices', 'Creating Sed', ...]
>>> cumulative_time, count, source = timers['Creating Sed']
>>> print(f"Total: {cumulative_time}s over {count} calls")
Total: 0.00035s over 3 calls
>>> print(timers.get_source('Creating Sed'))
'Python'
get_source(key)[source]

Get source (‘C’ or ‘Python’) for an operation.

This is used to determine linestyle in plots (solid for C, dashed for Python).

Parameters:

key (str) – Operation name.

Returns:

‘C’ or ‘Python’.

Return type:

str

Raises:

KeyError – If operation name doesn’t exist.

items()[source]

Iterate over (operation, timing_data) pairs.

Yields:

tuple – (operation_name, (cumulative_time, call_count, source)).

keys()[source]

Return list of operation names.

Returns:

List of operation names (str) that have accumulated timing

data.

Return type:

list

reset()[source]

Clear all accumulated timings.

This should be called before each profiling run to ensure fresh timing data is collected.