-1

I want to measure the performance speed of my method in runtime execution but i am not sure if what i have done is really measured the performance of my method i want or is doing something else. If it is measuring the performance speed of my method than how reliable it is. The method which i want to measure performance speed is called FFMulFast and it calculates the multiplication of two polynomials part of Galois Field (256). Note : i will present only code which is relevant to my question.

  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();

 }
Barlet South
  • 17
  • 1
  • 4
  • I don't know about "most reliable" but you should probably start with a standard tool like a profiler. – markspace May 25 '16 at 20:14
  • Well, there... isn't. The time you measure for, let's say, an execution is the time difference between two events - starting the stopwatch and stopping it. But what happened between those to events - full GC, OS stopped all JVM threads, etc. etc. - you never know. So more appropriate might be benchmarking - and there are ways to do it, well, correctly – micklesh May 25 '16 at 20:20
  • i thought the one i did is also benchmarking. – Barlet South May 25 '16 at 20:52

2 Answers2

1

Please take a look at jmh - http://openjdk.java.net/projects/code-tools/jmh/

Some more info about microbenchmarking:

  1. http://shipilev.net/talks/devoxx-Nov2013-benchmarking.pdf
  2. https://www.youtube.com/watch?v=vb62qrhfrtc
  3. Google "java microbenchmarking"
Alex K.
  • 714
  • 4
  • 14
0

This is perfectly fine when you are running your program in standalone. You can consider profiling/instrumentation for real time analysis in production like environment. Below post has a very good introduction for the same.

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

itsme_seenu
  • 340
  • 2
  • 8