java指标计算_java – 使用JMH计算指标

如何使用JMH计算CPU时间和内存量?

例如,我有:

码:

@State(Scope.Thread)

@BenchmarkMode(Mode.All)

public class JMHSample_My {

int x = 1;

int y = 2;

@GenerateMicroBenchmark

public int measureAdd() {

return (x + y);

}

@GenerateMicroBenchmark

public int measureMul() {

return (x * y);

}

public static void main(String[] args) throws RunnerException {

Options opt = new OptionsBuilder()

.include(".*" + JMHSample_My.class.getSimpleName() + ".*")

.warmupIterations(5)

.measurementIterations(5)

.forks(1)

.build();

new Runner(opt).run();

}

}

结果:

Benchmark Mode Samples Mean Mean error Units

JMHSample_My.measureAdd thrpt 5 1060579.757 39506.950 ops/ms

JMHSample_My.measureMul thrpt 5 1046872.684 79805.116 ops/ms

JMHSample_My.measureAdd avgt 5 0.000 0.000 ms/op

JMHSample_My.measureMul avgt 5 0.000 0.000 ms/op

JMHSample_My.measureAdd sample 9549793 0.000 0.000 ms/op

JMHSample_My.measureMul sample 9287002 0.000 0.000 ms/op

JMHSample_My.measureAdd ss 5 0.001 0.000 ms

JMHSample_My.measureMul ss 5 0.001 0.000 ms

我可以看到时间请求的数量,测试的平均时间,但没有看到平均CPU使用量和内存使用量.这可以通过JMH来完成吗?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值