-1

我想测量我的方法在运行时执行中的性能速度,但我不确定我所做的是否真的测量了我想要的方法的性能或正在做其他事情。如果它衡量的是我的方法的性能速度,那么它的可靠性就更高了。我想测量性能速度的方法称为 FFMulFast,它计算伽罗瓦域 (256) 的两个多项式部分的乘法。注意:我将只提供与我的问题相关的代码。

  public class GaloaField {

 // some fields here

     public int FFMulFast(int a, int b){
   int t = 0;;

  if (a == 0 || b == 0)

  return 0;

     /* The multiplication is done by using lookup tables. We have used both   logarithmic and exponential table for mul
    * the idea is firstly look to Logarithmic table then add their powers and find the corresponding of this to exponential table */

  t = (Log[(a & 0xff)] & 0xff) + (Log[(b & 0xff)] & 0xff);

 if (t > 255) t = t - 255;

 return Exp[(t & 0xff)];

 }

  //some other methods here

     public void runABunch() { //method which will measure the performance speed of FFMulFast
      long start = System.nanoTime();
       int a=0x56;
       int b=0xf4;
       for (int i = 0; i < 5000000; i++)
         FFMulFast(a,b);
       long end = System.nanoTime();
       System.out.println("Time: " + (end-start));
   }


   public static void main (String [] args) {

    GaloaField galoa=new GaloaField();

     galoa.runABunch();

 }
4

2 回答 2

1

请看一下 jmh - http://openjdk.java.net/projects/code-tools/jmh/

有关微基准测试的更多信息:

  1. http://shipilev.net/talks/devoxx-Nov2013-benchmarking.pdf
  2. https://www.youtube.com/watch?v=vb62qrhfrtc
  3. 谷歌“java 微基准测试”
于 2016-05-25T20:18:03.770 回答
0

当您以独立方式运行程序时,这非常好。您可以考虑在生产环境中进行分析/仪表化以进行实时分析。下面的帖子有一个很好的介绍。

http://blog.javabenchmark.org/2013/05/java-instrumentation-tutorial.html

于 2016-05-25T20:20:09.253 回答