Measuring time in Java

前端 未结 4 1200
粉色の甜心
粉色の甜心 2021-01-03 01:17

So I was trying to measure the time two different algorithm implementations took to accomplish a given task, and here is the result:

i    alg1  alg2
4   0.00         


        
4条回答
  •  孤城傲影
    2021-01-03 01:37

    You could instrument the code and count the number of bytecodes executed. You can do this with bycounter.

    This may not be ideal for your purposes. If the programs differ by only a very few bytecodes it may not give an accurate measure of which program is actually more performant, as the cost of executing bytecodes can vary wildly. Also, if there is network or disk reads during your program, the bytecode count could give the wrong comparison.

提交回复
热议问题