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 | 执行时间(纳秒)

public record BenchmarkResult(String name, long[] timesNanos) extends Record
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

    Constructors
    Constructor
    Description
    BenchmarkResult(String name, long[] timesNanos)
    Creates an instance of a BenchmarkResult record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    Gets the average time in milliseconds.
    double
    Gets the average time in nanoseconds.
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    int
    Gets the number of iterations.
    double
    Gets the maximum time in milliseconds.
    double
    Gets the median time in milliseconds.
    double
    Gets the minimum time in milliseconds.
    Returns the value of the name record component.
    double
    Gets the 95th percentile time in milliseconds.
    double
    Gets the 99th percentile time in milliseconds.
    double
    percentileMs(int percentile)
    Gets the percentile time in milliseconds.
    double
    Gets the standard deviation in milliseconds.
    Returns a formatted summary string.
    double
    Gets the throughput (operations per second).
    long[]
    Returns the value of the timesNanos record component.
    Returns a string representation of this record class.
    long
    Gets the total time in milliseconds.

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • BenchmarkResult

      public BenchmarkResult(String name, long[] timesNanos)
      Creates an instance of a BenchmarkResult record class.
      Parameters:
      name - the value for the name record component
      timesNanos - the value for the timesNanos record 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

      public String summary()
      Returns a formatted summary string. 返回格式化的摘要字符串。
      Returns:
      the summary | 摘要
    • toString

      public String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      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 with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • name

      public String name()
      Returns the value of the name record component.
      Returns:
      the value of the name record component
    • timesNanos

      public long[] timesNanos()
      Returns the value of the timesNanos record component.
      Returns:
      the value of the timesNanos record component