Class Benchmark
java.lang.Object
cloud.opencode.base.test.benchmark.Benchmark
Benchmark
基准测试
Simple benchmarking utility.
简单基准测试工具。
Features | 主要功能:
- Performance measurement utilities - 性能测量工具
- Comparison benchmarking - 对比基准测试
Usage Examples | 使用示例:
Duration time = Benchmark.time(() -> heavyOperation());
Benchmark.BenchmarkResult result = Benchmark.run("test", () -> operation());
Security | 安全性:
- Thread-safe: Yes (immutable) - 线程安全: 是(不可变)
- Since:
- JDK 25, opencode-base-test V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBenchmark result 基准测试结果static final recordComparison result 比较结果static final recordTimed result 计时结果 -
Method Summary
Modifier and TypeMethodDescriptionstatic Benchmark.ComparisonResultCompare two implementations 比较两个实现static Benchmark.BenchmarkResultRun benchmark with defaults 使用默认值运行基准测试static Benchmark.BenchmarkResultRun benchmark with warmup and iterations 运行带预热和迭代的基准测试static DurationMeasure execution time of runnable 测量可运行对象的执行时间static <T> Benchmark.TimedResult<T> Measure execution time with result 测量带结果的执行时间
-
Method Details
-
time
-
time
Measure execution time with result 测量带结果的执行时间- Type Parameters:
T- the result type | 结果类型- Parameters:
supplier- the supplier | 供应者- Returns:
- the result with timing | 带计时的结果
-
run
public static Benchmark.BenchmarkResult run(String name, Runnable runnable, int warmupIterations, int measureIterations) Run benchmark with warmup and iterations 运行带预热和迭代的基准测试- Parameters:
name- the benchmark name | 基准测试名称runnable- the runnable | 可运行对象warmupIterations- warmup iterations | 预热迭代次数measureIterations- measure iterations | 测量迭代次数- Returns:
- the result | 结果
-
run
Run benchmark with defaults 使用默认值运行基准测试- Parameters:
name- the name | 名称runnable- the runnable | 可运行对象- Returns:
- the result | 结果
-
compare
public static Benchmark.ComparisonResult compare(String name1, Runnable runnable1, String name2, Runnable runnable2) Compare two implementations 比较两个实现- Parameters:
name1- first name | 第一个名称runnable1- first runnable | 第一个可运行对象name2- second name | 第二个名称runnable2- second runnable | 第二个可运行对象- Returns:
- comparison result | 比较结果
-