-2

Why is my simple Java programm runs quickly on my local computer and too slow on Windows 2008 Server?

Programm code:

public static void main(String[] args) {
    long startTime;
    long endTime;
    long totalTime;

    startTime = System.currentTimeMillis();

    for (int a=1; a < 100000; a++) {
        System.out.println("Checking");

    }

    endTime   = System.currentTimeMillis();
    totalTime = endTime - startTime;
    System.out.println("TEST1 time:"+totalTime);

    startTime = System.currentTimeMillis();

    double sum = 0; 
    for (int a=1; a < 1000000; a++) {
        int input = 100;

        for(int counter=1;counter<input;counter++){
            sum += Math.pow(-1,counter + 1)/((2*counter) - 1);
        }

    }

    endTime   = System.currentTimeMillis();
    totalTime = endTime - startTime;
    System.out.println("TEST2 time:"+totalTime+" pi="+sum);
}

Local computer output:

Checking
Checking
Checking
Checking
TEST1 time:427
TEST2 time:7261 pi=787922.5634628027

Windows server output:

Checking
Checking
Checking
Checking
Checking
Checking
TEST1 time:15688
TEST2 time:25280 pi=787922.5634628027

Local computer hardware and soft: Intel Core (TM) i7-2600 CPU @ 3.40GHz Windows 7 Professional 8G RAM

Server hardware and soft:

Intel Xeon(R) CPU E5-2603 @ 1.60GHz 8G RAM Windows Server 2008 Standart Version 6.0

Both computer and server are free from another processes.

May be I have to apply some parametrs to java vm?

Leo
  • 1,029
  • 4
  • 19
  • 40
  • 1
    This is a microbenchmark - you're not testing a real-world problem but a tiny piece of code. That is very complicated and can be done wrong easily. In this case you're not warming up the VM by running the test first a few times; it's well possible that the VM interprets in one case and compiles in another. And of course the difference in CPU speeds. So it's not even clear why you expected them to be equally fast. – Erwin Bolwidt Sep 09 '16 at 05:49

3 Answers3

2

I would take a look at the differences in processor. Server systems are most of the time optimized for writing stuff to disk, not in doing calculations. Looking at the processor speeds alone, they are completely different 3.4 GHz vs 1.6 GHz based on that information only I would say the 3.4 should be much faster than the 1.6 GHz.

To be sure find some benchmark information on the two systems.

OblongZebra
  • 466
  • 5
  • 16
1

Of course, because the server processor is much slower, for me it seems perfectly fine result, from my calculations (for this test) the XEON 1.6 Ghz processor has 61% computation efficiency (per Ghz) of that i7 one. But, the i7 could also boost frequency from 3.4 to 3.8 Ghz on demand (Turbo Bost), so this could affect your test. Try to install another java VM and repeat that test. If you will be unsure after that, try running this on a linux (run an live linux image or something with java). There's many factors that can contribute to the result, memory speed is another one. You could also compare the processors GFLOPS values, this could give you a hint about efficiency, but as stated in some comment below your question, microbenchmarks are not very useful at measuring something.

Krzysztof Cichocki
  • 6,294
  • 1
  • 16
  • 32
0

When you test sub-optimal code which you wouldn't normally write you are testing some of the specific behaviour of that processor. There is every chance one processor design might perform one operation much slower than another but on balance in real programs this doesn't show up.

The simplest solution is attempt to optimise the code and you might find it's much faster on both machines.

double sum = 0; 
for (int a=1; a < 1000000; a++) {
    int input = 100;

    for(int counter = 1; counter < input; counter += 2){
        sum += 1.0 / (2 * counter - 1) - 1 / (2 * counter + 1);
        // or
        // sum += 2.0 / ((2 * counter - 1) * (2 * counter + 1));
    }
}

Note: Math.pow is a very expensive operation.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130