| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- /**
- * ContainerBenchmark - Benchmarks for Container entity operations
- *
- * Measures performance of container creation, child enumeration,
- * and deletion operations.
- *
- * @version 0.1
- * @since 0.1
- */
- namespace Implexus.Tools.Perf {
- /**
- * Benchmark for Container entity operations.
- *
- * Tests:
- * - create_container: Creating new containers
- * - get_children: Enumerating container children
- * - get_child: Getting individual child by name
- * - delete_container: Deleting containers (tracked for deferred cleanup)
- */
- public class ContainerBenchmark : Benchmark {
-
- /**
- * {@inheritDoc}
- */
- public override string name { get { return "Container"; } }
-
- /**
- * Creates a new ContainerBenchmark.
- *
- * @param engine The engine to benchmark
- * @param config The benchmark configuration
- */
- public ContainerBenchmark(Core.Engine engine, BenchmarkConfig config) {
- base(engine, config);
- }
-
- /**
- * {@inheritDoc}
- */
- public override async void run_async(Results results) throws Error {
- var parent_path = new Core.EntityPath("/perf-test");
- var containers_path = parent_path.append_child("containers");
-
- // Ensure parent container exists
- yield ensure_container_async(parent_path, "perf-test");
- _cleanup_tracker.add_container(parent_path.to_string());
-
- // Create a dedicated container for our tests
- yield cleanup_path_async(containers_path);
- var root = yield _engine.get_root_async();
- var perf_test = yield root.get_child_async("perf-test");
- var containers = yield perf_test.create_container_async("containers");
- _cleanup_tracker.add_container(containers_path.to_string());
-
- int iterations = _config.iterations;
-
- // Test 1: Create containers
- print(" Testing create_container (%d iterations)...\n", iterations);
- var create_op = new CreateContainerOperation(this, containers_path, containers);
- var create_result = yield measure_async("create_container", iterations, create_op);
- results.add(name, create_result);
-
- // Test 2: Get container children
- print(" Testing get_children (%d iterations)...\n", iterations);
- var get_op = new GetChildrenOperation(containers);
- var get_result = yield measure_async("get_children", iterations, get_op);
- results.add(name, get_result);
-
- // Test 3: Get individual child by name
- print(" Testing get_child (%d iterations)...\n", iterations);
- var get_child_op = new GetChildOperation(containers, iterations);
- var get_child_result = yield measure_async("get_child", iterations, get_child_op);
- results.add(name, get_child_result);
-
- // Test 4: Delete containers (still tracked for deferred cleanup)
- print(" Testing delete_container (%d iterations)...\n", iterations);
- var delete_op = new DeleteContainerOperation(this, _engine, containers_path);
- var delete_result = yield measure_async("delete_container", iterations, delete_op);
- results.add(name, delete_result);
- }
- }
- // Operation classes for ContainerBenchmark
- private class CreateContainerOperation : AsyncOperation {
- private ContainerBenchmark _benchmark;
- private Core.EntityPath _containers_path;
- private Core.Entity _containers;
-
- public CreateContainerOperation(ContainerBenchmark benchmark, Core.EntityPath containers_path, Core.Entity containers) {
- _benchmark = benchmark;
- _containers_path = containers_path;
- _containers = containers;
- }
-
- public override async void execute_async() throws Error {
- var container_name = "container-%d".printf(iteration);
- var container_path = _containers_path.append_child(container_name);
- // Clean up before creating to ensure consistent state
- yield _benchmark.cleanup_path_async(container_path);
- yield _containers.create_container_async(container_name);
- // Track for deferred cleanup
- _benchmark._cleanup_tracker.add_container(container_path.to_string());
- }
- }
- private class GetChildrenOperation : AsyncOperation {
- private Core.Entity _containers;
-
- public GetChildrenOperation(Core.Entity containers) {
- _containers = containers;
- }
-
- public override async void execute_async() throws Error {
- var children = yield _containers.get_children_async();
- // Force enumeration by counting
- int count = 0;
- foreach (var child in children) {
- count++;
- }
- }
- }
- private class GetChildOperation : AsyncOperation {
- private Core.Entity _containers;
- private int _total_iterations;
-
- public GetChildOperation(Core.Entity containers, int total_iterations) {
- _containers = containers;
- _total_iterations = total_iterations;
- }
-
- public override async void execute_async() throws Error {
- var container_name = "container-%d".printf(iteration % _total_iterations);
- var child = yield _containers.get_child_async(container_name);
- }
- }
- private class DeleteContainerOperation : AsyncOperation {
- private ContainerBenchmark _benchmark;
- private Core.Engine _engine;
- private Core.EntityPath _containers_path;
-
- public DeleteContainerOperation(ContainerBenchmark benchmark, Core.Engine engine, Core.EntityPath containers_path) {
- _benchmark = benchmark;
- _engine = engine;
- _containers_path = containers_path;
- }
-
- public override async void execute_async() throws Error {
- var container_name = "container-%d".printf(iteration);
- var path = _containers_path.append_child(container_name);
- var entity = yield _engine.get_entity_or_null_async(path);
- if (entity != null) {
- yield ((!) entity).delete_async();
- }
- }
- }
- }
|