Record Class BenchmarkResult
java.lang.Object
java.lang.Record
cloud.opencode.base.test.benchmark.BenchmarkResult
- Record Components:
name- the benchmark name | 基准测试名称timesNanos- the execution times in nanoseconds | 执行时间(纳秒)
Benchmark Result - Immutable result of a benchmark run
基准测试结果 - 基准测试运行的不可变结果
Contains timing statistics for a benchmark execution.
包含基准测试执行的计时统计。
Features | 主要功能:
- Average, min, max timing statistics - 平均、最小、最大计时统计
- Percentile calculations (p50, p95, p99) - 百分位计算
- Throughput and standard deviation - 吞吐量和标准差
- Formatted summary output - 格式化摘要输出
Usage Examples | 使用示例:
BenchmarkResult result = BenchmarkRunner.runSingle("test", () -> doWork());
System.out.println("Average: " + result.averageMs() + "ms");
System.out.println("P95: " + result.p95Ms() + "ms");
System.out.println(result.summary());
Security | 安全性:
- Thread-safe: Yes (immutable record) - 线程安全: 是(不可变记录)
- Null-safe: No (requires non-null timesNanos array) - 空值安全: 否(需要非空timesNanos数组)
- Since:
- JDK 25, opencode-base-test V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionBenchmarkResult(String name, long[] timesNanos) Creates an instance of aBenchmarkResultrecord class. -
Method Summary
Modifier and TypeMethodDescriptiondoubleGets the average time in milliseconds.doubleGets the average time in nanoseconds.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.intGets the number of iterations.doublemaxMs()Gets the maximum time in milliseconds.doublemedianMs()Gets the median time in milliseconds.doubleminMs()Gets the minimum time in milliseconds.name()Returns the value of thenamerecord component.doublep95Ms()Gets the 95th percentile time in milliseconds.doublep99Ms()Gets the 99th percentile time in milliseconds.doublepercentileMs(int percentile) Gets the percentile time in milliseconds.doublestdDevMs()Gets the standard deviation in milliseconds.summary()Returns a formatted summary string.doubleGets the throughput (operations per second).long[]Returns the value of thetimesNanosrecord component.toString()Returns a string representation of this record class.longtotalMs()Gets the total time in milliseconds.
-
Constructor Details
-
BenchmarkResult
Creates an instance of aBenchmarkResultrecord class.- Parameters:
name- the value for thenamerecord componenttimesNanos- the value for thetimesNanosrecord component
-
-
Method Details
-
iterations
public int iterations()Gets the number of iterations. 获取迭代次数。- Returns:
- the iteration count | 迭代次数
-
averageMs
public double averageMs()Gets the average time in milliseconds. 获取平均时间(毫秒)。- Returns:
- the average time | 平均时间
-
averageNanos
public double averageNanos()Gets the average time in nanoseconds. 获取平均时间(纳秒)。- Returns:
- the average time | 平均时间
-
minMs
public double minMs()Gets the minimum time in milliseconds. 获取最小时间(毫秒)。- Returns:
- the minimum time | 最小时间
-
maxMs
public double maxMs()Gets the maximum time in milliseconds. 获取最大时间(毫秒)。- Returns:
- the maximum time | 最大时间
-
percentileMs
public double percentileMs(int percentile) Gets the percentile time in milliseconds. 获取百分位时间(毫秒)。- Parameters:
percentile- the percentile (0-100) | 百分位- Returns:
- the percentile time | 百分位时间
-
medianMs
public double medianMs()Gets the median time in milliseconds. 获取中位数时间(毫秒)。- Returns:
- the median time | 中位数时间
-
p95Ms
public double p95Ms()Gets the 95th percentile time in milliseconds. 获取第95百分位时间(毫秒)。- Returns:
- the p95 time | P95时间
-
p99Ms
public double p99Ms()Gets the 99th percentile time in milliseconds. 获取第99百分位时间(毫秒)。- Returns:
- the p99 time | P99时间
-
totalMs
public long totalMs()Gets the total time in milliseconds. 获取总时间(毫秒)。- Returns:
- the total time | 总时间
-
throughputPerSecond
public double throughputPerSecond()Gets the throughput (operations per second). 获取吞吐量(每秒操作数)。- Returns:
- the throughput | 吞吐量
-
stdDevMs
public double stdDevMs()Gets the standard deviation in milliseconds. 获取标准差(毫秒)。- Returns:
- the standard deviation | 标准差
-
summary
-
toString
-
hashCode
-
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object). -
name
-
timesNanos
public long[] timesNanos()Returns the value of thetimesNanosrecord component.- Returns:
- the value of the
timesNanosrecord component
-