Today faced with one thing that I would like to make out.

Here is an example of a simple task.

Task

and my decision

public static void main(String [] args){ Scanner sc = new Scanner(System.in); long n = sc.nextLong(); long m = sc.nextLong(); long a = sc.nextLong(); System.out.print((long)Math.ceil((double) n/a)* (long)Math.ceil((double)m/a)); } 

when compiled on java8, the result is 280 ms. Not really. Then I decided to compile it on java7 and got 156 ms. The difference is very noticeable on such trifles.

The question is: why does java8 work 2 times slower on such trifles, and in the future is it worth to focus on java7?

  • 2
    IMHO, much more important is not the compilation time, but the time spent on program execution. That's what you need to measure. - Hermann Zheboldov
  • What is this result? Who got it? How exactly did you get it? 99.99999% - probability that the measurement was taken incorrectly. - a_gura

1 answer 1

@Gaponec , I assume that this is some initialization costs. To check this assumption, you can wrap the application code directly into the loop and run it many times, in this case, any initialization costs are leveled by the long execution of the working code itself, and you will have more information to think about.

Plus, for sure, there are java profilers that will help you figure out the exact time of the execution of the real code.