calibrax.core.registry¤
Benchmark registry for discovering and looking up benchmark classes by name.
Use the @register_benchmark decorator to register classes and get_benchmark()
to retrieve them.
Generic type-safe registry and benchmark registry singleton.
Provides a reusable Registry[T] for named item storage, a SingletonRegistry[T] for shared-instance registries, a BenchmarkRegistry singleton specialization, and convenience functions for benchmark registration.
Registry()
¤
Bases: Generic[T]
Generic type-safe registry for named items.
Supports register, get, remove, clear, and iteration. Not a singleton — allows multiple independent instances.
Initialize an empty registry.
register(name, item)
¤
Register an item under the given name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Unique name for the item. |
required |
item
|
T
|
The item to register. |
required |
get(name)
¤
Retrieve an item by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name of the item to retrieve. |
required |
Returns:
| Type | Description |
|---|---|
T
|
The registered item. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If no item is registered under the given name. |
list_names()
¤
Return all registered names.
Returns:
| Type | Description |
|---|---|
list[str]
|
List of registered item names. |
has(name)
¤
Check if a name is registered.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name to check. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the name is registered. |
remove(name)
¤
Remove an item by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name of the item to remove. |
required |
Raises:
| Type | Description |
|---|---|
KeyError
|
If no item is registered under the given name. |
clear()
¤
Remove all registered items.
__len__()
¤
Return the number of registered items.
__contains__(name)
¤
Check if a name is registered.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
object
|
Name to check. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the name is registered. |
__iter__()
¤
Iterate over registered names.
SingletonRegistry()
¤
Bases: Registry[T]
Registry that enforces a single shared instance per subclass.
Subclasses inherit register/get/remove/clear/iteration from Registry[T] and gain automatic singleton semantics with a reset() classmethod for test isolation.
Usage
class MyRegistry(SingletonRegistry[MyItem]): '''Project-specific singleton registry.'''
No-op init to prevent re-initialization of singleton state.
BenchmarkRegistry()
¤
Bases: SingletonRegistry[object]
Singleton registry for benchmark implementations.
Ensures a single shared registry instance across the application. Provides reset() for test isolation.
register_benchmark(name)
¤
Class decorator that registers a class into the BenchmarkRegistry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name to register the class under. |
required |
Returns:
| Type | Description |
|---|---|
Callable[[_C], _C]
|
Decorator that registers the class and returns it unchanged. |
get_benchmark(name)
¤
Retrieve a benchmark by name from the singleton registry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name of the benchmark. |
required |
Returns:
| Type | Description |
|---|---|
object
|
The registered benchmark. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If no benchmark is registered under the given name. |
list_benchmarks()
¤
List all registered benchmark names.
Returns:
| Type | Description |
|---|---|
list[str]
|
List of registered benchmark names. |