Class BenchmarkBuilder

java.lang.Object
com.codingchili.core.benchmarking.BenchmarkBuilder
All Implemented Interfaces:
Benchmark, BenchmarkResult

public class BenchmarkBuilder extends Object implements Benchmark
Base implementation of a benchmark.
  • Constructor Details

    • BenchmarkBuilder

      public BenchmarkBuilder(String name)
      Creates a new benchmark builder.
      Parameters:
      name - the name of the benchmark to build.
  • Method Details

    • setIterations

      public BenchmarkBuilder setIterations(int iterations)
      Specified by:
      setIterations in interface Benchmark
      Parameters:
      iterations - the number of iterations this benchmark will be executed for.
      Returns:
      fluent
    • setName

      public void setName(String name)
      Specified by:
      setName in interface Benchmark
      Parameters:
      name - the name of the benchmark to set.
    • setOperation

      public BenchmarkBuilder setOperation(BenchmarkOperation operation)
    • start

      public Benchmark start()
      Description copied from interface: Benchmark
      Start measuring of the execution time.
      Specified by:
      start in interface Benchmark
      Returns:
      fluent
    • finish

      public void finish()
      Description copied from interface: Benchmark
      Finish benchmarking: calculates the results.
      Specified by:
      finish in interface Benchmark
    • isFinished

      public boolean isFinished()
      Specified by:
      isFinished in interface Benchmark
      Returns:
      returns true if Benchmark.finish() has been called.
    • getElapsedMS

      public long getElapsedMS()
      Specified by:
      getElapsedMS in interface Benchmark
      Returns:
      the time taken to complete the benchmark in ms.
    • getOperation

      public BenchmarkOperation getOperation()
      Description copied from interface: Benchmark
      The operation to benchmark.
      Specified by:
      getOperation in interface Benchmark
      Returns:
      an executable benchmark.
    • getName

      public String getName()
      Description copied from interface: Benchmark
      The handler of the single benchmark operation to run. Should typically match the method handler.
      Specified by:
      getName in interface Benchmark
      Returns:
      a string that identifies the handler the Benchmark operation.
    • setProperty

      public Benchmark setProperty(String key, Object value)
      Description copied from interface: Benchmark
      Sets a property on the benchmark object, may be a parameter or a result.
      Specified by:
      setProperty in interface Benchmark
      Parameters:
      key - the key to identify this property
      value - the value to insert
      Returns:
      fluent
    • getProperties

      public Map<String,​Object> getProperties()
      Description copied from interface: Benchmark
      get all properties added to the implementation.
      Specified by:
      getProperties in interface Benchmark
      Returns:
      a map of all the properties that has been set.
    • getTimeFormatted

      public String getTimeFormatted()
      Specified by:
      getTimeFormatted in interface BenchmarkResult
      Returns:
      time formatted as HH:mm:ss.SSS using the elapsed ms as source.
    • getRateFormatted

      public String getRateFormatted()
      Specified by:
      getRateFormatted in interface BenchmarkResult
      Returns:
      the number of operations per second as a formatted string.
    • getRate

      public int getRate()
      Specified by:
      getRate in interface BenchmarkResult
      Returns:
      the number of operations per second.