Raxol.Test.PerformanceHelper (Raxol v0.5.0)

View Source

Provides utilities for performance testing and benchmarking in Raxol.

This module includes:

  • Benchmarking utilities
  • Performance test setup and teardown
  • Common performance test scenarios
  • Metrics collection and reporting

Summary

Functions

Asserts that a set of concurrent operations' average execution time is below a threshold.

Asserts that an operation's memory usage is below a threshold.

Asserts that an operation's average execution time is below a threshold. Use this for direct operation timing, not for benchmark result structs.

Asserts that a benchmark meets performance requirements.

Runs a benchmark with the given function and options.

Calculates the nth percentile from a list of times.

Formats benchmark results for human-readable output.

Measures the average execution time of an operation over multiple iterations. Returns the average time in milliseconds.

Measures memory usage of an operation. Returns {memory_in_bytes, result}.

Measures the execution time of an operation. Returns {time_in_ms, result}.

Sets up a test environment optimized for performance testing.

Functions

assert_concurrent_performance(operations, name, threshold \\ 0.002, iterations \\ 1000)

Asserts that a set of concurrent operations' average execution time is below a threshold.

assert_memory_usage(operation, name, threshold \\ 1_000_000)

Asserts that an operation's memory usage is below a threshold.

assert_operation_performance(operation, name, threshold \\ 0.001, iterations \\ 1000)

Asserts that an operation's average execution time is below a threshold. Use this for direct operation timing, not for benchmark result structs.

assert_performance(benchmark_result, opts \\ [])

Asserts that a benchmark meets performance requirements.

Options

  • :max_average_time - Maximum allowed average time in microseconds
  • :max_p95_time - Maximum allowed 95th percentile time in microseconds
  • :min_iterations - Minimum number of iterations required

assert_performance_metrics(operation, name, time_threshold \\ 0.001, memory_threshold \\ 1_000_000)

Measures and asserts both time and memory performance.

benchmark(fun, opts \\ [])

Runs a benchmark with the given function and options.

Options

  • :iterations - Number of iterations to run (default: 1000)
  • :warmup - Number of warmup iterations (default: 100)
  • :timeout - Maximum time to run in milliseconds (default: 5000)

calculate_percentile(times, percentile)

Calculates the nth percentile from a list of times.

format_benchmark_results(results)

Formats benchmark results for human-readable output.

measure_average_time(operation, iterations \\ 1000)

Measures the average execution time of an operation over multiple iterations. Returns the average time in milliseconds.

measure_memory(operation)

Measures memory usage of an operation. Returns {memory_in_bytes, result}.

measure_time(operation)

Measures the execution time of an operation. Returns {time_in_ms, result}.

setup_performance_test_env()

Sets up a test environment optimized for performance testing.

Returns a context map with initialized services and performance monitoring.