Class BenchmarkRunner
java.lang.Object
cloud.opencode.base.test.benchmark.BenchmarkRunner
Benchmark Runner - Configurable benchmark test runner
基准测试运行器 - 可配置的基准测试运行器
Provides a fluent API for running and comparing benchmarks.
提供用于运行和比较基准测试的流式API。
Features | 主要功能:
- Configurable warmup and measurement iterations - 可配置的预热和测量迭代
- Multiple benchmark comparison - 多基准测试比较
- Timeout protection - 超时保护
- Formatted results output with comparison - 格式化结果输出与比较
Usage Examples | 使用示例:
BenchmarkRunner runner = BenchmarkRunner.create()
.warmup(100)
.iterations(1000)
.add("ArrayList", () -> new ArrayList<>().add("test"))
.add("LinkedList", () -> new LinkedList<>().add("test"));
List<BenchmarkResult> results = runner.run();
runner.printResults();
Security | 安全性:
- Thread-safe: No (not designed for concurrent use) - 线程安全: 否(非设计用于并发使用)
- Null-safe: Yes (validates non-null inputs) - 空值安全: 是(验证非空输入)
- Since:
- JDK 25, opencode-base-test V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionAdds benchmark.<T> BenchmarkRunnerAdds benchmark with return value (result ignored).static BenchmarkRunnercreate()Creates new benchmark runner.Gets the results (must call run() first).iterations(int iterations) Sets measure iterations.onComplete(Consumer<List<BenchmarkResult>> consumer) Executes callback with results.output(PrintStream output) Sets output stream.Prints comparison of results.Prints results to output stream.run()Runs all benchmarks.static BenchmarkResultCreates and runs single benchmark.Sets timeout for each benchmark.verbose()Enables verbose output.warmup(int iterations) Sets warmup iterations.
-
Method Details
-
create
Creates new benchmark runner. 创建新的基准测试运行器。- Returns:
- the runner | 运行器
-
runSingle
Creates and runs single benchmark. 创建并运行单个基准测试。- Parameters:
name- the benchmark name | 基准测试名称runnable- the code to benchmark | 要基准测试的代码- Returns:
- the result | 结果
-
warmup
Sets warmup iterations. 设置预热迭代次数。- Parameters:
iterations- the iterations | 迭代次数- Returns:
- this | 此对象
-
iterations
Sets measure iterations. 设置测量迭代次数。- Parameters:
iterations- the iterations | 迭代次数- Returns:
- this | 此对象
-
timeout
Sets timeout for each benchmark. 设置每个基准测试的超时时间。- Parameters:
timeout- the timeout | 超时时间- Returns:
- this | 此对象
-
output
Sets output stream. 设置输出流。- Parameters:
output- the output stream | 输出流- Returns:
- this | 此对象
-
verbose
-
add
Adds benchmark. 添加基准测试。- Parameters:
name- the benchmark name | 基准测试名称runnable- the code to benchmark | 要基准测试的代码- Returns:
- this | 此对象
-
add
Adds benchmark with return value (result ignored). 添加带返回值的基准测试(忽略结果)。- Type Parameters:
T- the return type | 返回类型- Parameters:
name- the benchmark name | 基准测试名称callable- the code to benchmark | 要基准测试的代码- Returns:
- this | 此对象
-
run
-
getResults
Gets the results (must call run() first). 获取结果(必须先调用run())。- Returns:
- the results | 结果列表
-
printResults
Prints results to output stream. 将结果打印到输出流。- Returns:
- this | 此对象
-
printComparison
-
onComplete
Executes callback with results. 使用结果执行回调。- Parameters:
consumer- the consumer | 消费者- Returns:
- this | 此对象
-