Linux speed

Discussion in 'Linux, BSD and Other OS's' started by cipicip, Apr 29, 2005.

  1. cipicip

    cipicip Geek Trainee

    Likes Received:
    0
    Trophy Points:
    0
    Hi guys!

    I got a puzzle for you.

    During a period of boredom , I wrote this little program in java (initially was in C++) and ran it on WinXPpro and Linux FC3. Basically it’s a benchmark program. Returns the total number of cycles the program executes in 30 seconds.

    And surprise! The windows executes around 200 millions cycles, while the Linux around 20 millions. The C++ version returned even a greater difference 320 : 15 which made me consider the possibility that this problem might have something to do with the compiler (VS 2003 vs. g++) and so wrote the same program in java.

    My pc is a dual boot P4 @3GHz 800MHz bus. I stopped almost every service in Linux (except for network and some others related with the optimization) even if the Windows runs lots of services too.

    Can anyone replicate these results? Can anyone explain this?

    And for those of you who might be wondering, I’m not a Windows fan nor a Linux one.


    //------------------- START ------------------------

    import java.util.*;


    public class Benchmark {

    public static void main(String[] args) {

    int k = 0;
    long counter = 0;
    long presentNoSec = 0;
    long initialNoSec = 0;
    float[] values = new float[1000];

    Date refDate = new Date();
    initialNoSec = refDate.getTime();


    for(int i=0; i< 1000 ; i++)
    {
    values = (float)(Math.random() * 1000);
    }



    System.out.println("And here we go...");

    for(counter=0; (presentNoSec - initialNoSec) < (30 * 1000) ; counter++)
    {
    refDate = new Date();
    presentNoSec = refDate.getTime();

    if(k%2 == 0)
    values[k] /= values[k + 500];
    else
    values[k] += values[k + 500];


    k++;

    if(k>=500)
    k=0;
    }

    System.out.println("Total no. of cicles: " + Long.toString(counter));

    }
    }
    //----------------- END -----------------------
     
  2. Addis

    Addis The King

    Likes Received:
    91
    Trophy Points:
    48
    I think its the compiler you're using. Try using the MinGW compiler for windows and see if its the vcc compiler that could be causing anomalous results.
     
  3. cipicip

    cipicip Geek Trainee

    Likes Received:
    0
    Trophy Points:
    0
    Maybe, but I wrote the same app in java, compiled it with sun compiler and got similar results. So I think this problem goes beyond the compiler. :(
     
  4. Addis

    Addis The King

    Likes Received:
    91
    Trophy Points:
    48
    strange problem indeed. Can you post the source for c++ i don't do java.
     
  5. cipicip

    cipicip Geek Trainee

    Likes Received:
    0
    Trophy Points:
    0
    Here it is. This is the original version of the program. Afterwards - in the java version - I added the random number generator section to prevent the OS (or CPU or whatever) to build some sort of cache and return the results from it (I know it's a bit Sci-Fi - or at least I know nothing about such a feature - but it's the only explanation my friends and I could come up with :) ):



    //------------------------ START CODE ---------------------------------
    #include <stdio.h>
    #include <time.h>


    int main()
    {
    time_t initialTime;
    time_t testTime;
    long counter = 0;
    double test = 1;


    time(&initialTime);
    testTime = initialTime;

    printf("Here we go...\n");

    while((testTime-initialTime) < 30)
    {
    time(&testTime);
    test /= 10;
    test *= 10;
    test += 10;
    test -= 10;

    counter ++;

    }

    printf("No. of cycles: %ld\n", counter);

    return 0;
    }

    //------------------------- END CODE ------------------
     
  6. Addis

    Addis The King

    Likes Received:
    91
    Trophy Points:
    48
    Ok I'll compile and check it out and post back with any results.
     
  7. Addis

    Addis The King

    Likes Received:
    91
    Trophy Points:
    48
    compiled with gcc and MinGW and get same results as you. Around 18million with linux and 320 with Windows. Maybe some kernel differences between them that cause this, as linux generally performs >= windows.
     
  8. cipicip

    cipicip Geek Trainee

    Likes Received:
    0
    Trophy Points:
    0
    Thanks for testing it.

    I'm using kernel version 6 (since it's FC3 :) ) What's your kernel version? And what CPU do you have, AMD? Maybe it's a hardware thing - I'm sure you've heard the rumors about the secret deal between MS and Intel ;) But if you have AMD then it should be a software issue.
     
  9. Addis

    Addis The King

    Likes Received:
    91
    Trophy Points:
    48
    Using Mandrake 10.1 with default 2.6.8-12mdk kernel. AMD AthlonXP 2700 CPU, it might just be the way the kernel does monotonous iterations. But it shouldn't be a problem since linux performs very well normal apps, probably a feature of linux itself.
     
  10. cipicip

    cipicip Geek Trainee

    Likes Received:
    0
    Trophy Points:
    0
    Thank you very much Addis.
     

Share This Page