public abstract class Benchmark<T> extends Object
| 限定符和类型 | 字段和说明 |
|---|---|
protected Executable |
executable |
protected Set<Reporter> |
reporters |
protected ExecutorService |
service |
protected int |
threads |
| 限定符 | 构造器和说明 |
|---|---|
protected |
Benchmark(int threads,
Executable executable) |
| 限定符和类型 | 方法和说明 |
|---|---|
T |
addReporter(Reporter reporter)
设置报告生成器
Reporter.console() - 将压测信息打印到终端
|
void |
benchmark()
开始压测
|
protected void |
execute() |
String |
name() |
T |
name(String name)
命名压测对象
|
static CountBenchmark |
ofCount(int count,
int threads,
Executable executable)
创建一个计数的性能测试实例
|
static TimingBenchmark |
ofTiming(Duration duration,
int threads,
Executable executable)
创建一个计时的性能测试实例
|
protected abstract CountDownLatch |
prepare(CountDownLatch latch) |
int |
threads() |
protected final Executable executable
protected final ExecutorService service
protected final int threads
protected Benchmark(int threads,
Executable executable)
public static TimingBenchmark ofTiming(Duration duration, int threads, Executable executable)
duration - 测试的时间段,不可为 nullthreads - 测试线程数,必须为正整数executable - 测试内容,不可为 nullTimingBenchmark 对象public static CountBenchmark ofCount(int count, int threads, Executable executable)
count - 测试次数threads - 测试线程数executable - 测试内容,不可为 nullCountBenchmark 对象public T addReporter(Reporter reporter)
Reporter.console() - 将压测信息打印到终端reporter - 报告生成器,不可为 nullpublic void benchmark()
public String name()
public int threads()
protected abstract CountDownLatch prepare(CountDownLatch latch)
protected void execute()
Copyright © 2022. All rights reserved.