计算为Java代码执行的字节代码的最佳方法 [英] Best method to count byte codes executed for a Java code

查看:159
本文介绍了计算为Java代码执行的字节代码的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图获取各种Java程序的时序数据.然后,我必须根据此时序数据执行一些回归分析.这是我用来获取计时数据的两种方法:

I was trying to get timing data for various Java programs. Then I had to perform some regression analysis based on this timing data. Here are the two methods I used to get the timing data:

  • System.currentTimeMillis():最初使用此方法,但是当同一程序多次运行时,我希望定时数据保持恒定 时代.在这种情况下,变化很大.当两个实例 相同的代码并行执行,变化更大.所以 我放弃了这个,开始寻找一些探查器.
  • -XX热点JVM中的-XX countBytecodes标志:由于计时数据的差异很大,因此我想到了在执行该代码时要测量执行的字节代码的数量.当同一程序多次执行时,它应该具有更多的静态计数.但这也有变化.当顺序执行程序时,变化很小,但是在相同代码的并行运行期间,变化很大.我还尝试使用-Xint进行编译,但结果相似.
  • System.currentTimeMillis(): I used this initially, but I wanted the timing data to be constant when the same program was run multiple times. The variation was huge in this case. When two instances of the same code were executed in parallel, the variation was even more. So I dropped this and started looking for some profilers.
  • -XX countBytecodes Flag in Hotspot JVM: Since the variation in timing data was huge, I thought of measuring the number of byte codes executed, when this code was executed. This should have given a more static count, when the same program was executed multiple times. But This also had variations. When the programs were executed sequentially, the variations were small, but during parellel runs of the same code, the variations were huge. I also tried compiling using -Xint, but the results were similar.

因此,我正在寻找一些探查器,该探查器可以为我提供在执行代码时执行的字节代码的计数.在同一程序的运行期间,计数应保持恒定(或相关性接近1).或者,如果可以根据其他指标来获取计时数据,那么在多次运行中,该数据应该几乎保持不变.

So I am looking for some profiler that could give me the count of byte codes executed when a code is executed. The count should remain constant (or correlation close to 1) across runs of the same program. Or if there could be some other metric based on which I could get timing data, which should stay almost constant across multiple runs.

推荐答案

当同一程序多次运行时,我希望定时数据是恒定的

I wanted the timing data to be constant when the same program was run multiple times

除非是为硬实时系统设计的,否则在实际机器上是不可能的,而您的机器几乎肯定不会这样做.

That is not possible on a real machine unless it is designed for hard real time system which your machine will almost certainly be not.

我正在寻找一些探查器,该探查器可以让我了解执行代码时执行的字节代码的数量.

I am looking for some profiler that could give me the count of byte codes executed when a code is executed.

假设您可以执行此操作,那么它什么也不会证明.例如,您将无法看到++%便宜90倍,具体取决于运行它的硬件.您将无法看到if的分支未命中比推测分支的代价高100倍之多.您将无法看到对导致TLB未命中的内存区域的内存访问可能比复制4 KB数据要昂贵得多.

Assuming you could do this, it wouldn't prove anything. You wouldn't be able to see for example that ++ is 90x cheaper than % depending on the hardware you run it on. You won't be able to see that a branch miss of an if is up to 100x more expensive than a speculative branch. You wouldn't be able to see that a memory access to an area of memory which triggers a TLB miss can be more expensive than copying 4 KB of data.

如果还有其他一些指标可以用来获取计时数据,那么在多次运行中该数据应该几乎保持不变.

if there could be some other metric based on which I could get timing data, which should stay almost constant across multiple runs.

您可以运行多次并取平均值.这将隐藏任何较高的结果/异常值,并为您提供吞吐量的理想方法.如果运行足够长的时间,则它对于给定的机器而言可以是可复制的数字.

You can run it many times and take the average. This will hide any high results/outliers and give you a favourable idea of throughput. It can be a reproducible number for a given machine, if run long enough.

这篇关于计算为Java代码执行的字节代码的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆