Run time differences in Linux gcc versions

This is a discussion on Run time differences in Linux gcc versions within the C++ Programming forums, part of the General Programming Boards category; Hi all, In my home computer I've got Slackware 12 with gcc 4.1.2. I wrote a C++ program (could attach ...

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    28

    Run time differences in Linux gcc versions

    Hi all,
    In my home computer I've got Slackware 12 with gcc 4.1.2. I wrote a C++ program (could attach the code if you want) and I got a run time of around 2.2s. I transferred the same C++ program to my work computer that has Fedora Core 4 with gcc 4.0.0 and I found that it takes 16s to run. The work computer has more RAM (1 GB) than my home computer (512 MB) and both are AMD 64 bit proc.

    I compiled and installed gcc 4.1.2 in my work computer and now find the run times have reduced to 2.2s. Is there a difference in the gcc compiler versions?

    Thanks.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Ehm, quite obviously the answer to that is "Yes".

    What the difference is, and how why that makes so much difference in this case is something we could only [possibly] say by looking at the code [and more likely by investigating the difference in the produced assembler code].

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,251
    gcc can change very dramatically from version to version. The difference is not surprising.

  4. #4
    Registered User
    Join Date
    Feb 2008
    Posts
    28
    Thanks for the responses.

    I am attaching the program.
    Attached Files Attached Files

  5. #5
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Especially if the program does something that is very well optimized by a new optimizer in the new version.

    Note also that 4.1 is a big improvement over 4.0. 4.0 introduced a new optimization framework, but only 4.1 really makes use of it. 4.0 is also said to be quite riddled with bugs. You shouldn't use it.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  6. #6
    Registered User
    Join Date
    Sep 2006
    Posts
    835
    If you didn't try various optimization levels (-ON for various values of N, 0 is the default) with both versions, it's possible that 4.1.2 was able to optimize at default level something that 4.0.0 would need a higher level to be able to find.

  7. #7
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Yes, I would say that optimization levels may affect the code efficiency, and the x.0 versions of gcc often have limitations in the efficency of new features, whilst the later update versions are much better at using these new features.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  8. #8
    Registered User
    Join Date
    Feb 2008
    Posts
    28
    Using the -ON optimization options reduces run times to 9.6s. I used all various levels but couldn't get run times lesser than that. Guess I'll use gcc 4.1.2 on all my computers.

    Thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. time measure (net and gross) with pthreads under linux
    By mynickmynick in forum Linux Programming
    Replies: 12
    Last Post: 12-01-2008, 06:39 AM
  2. stdio differences windows vs linux
    By keira in forum C Programming
    Replies: 6
    Last Post: 09-14-2008, 04:42 PM
  3. How to time how long a program takes to run?
    By advancedk in forum C Programming
    Replies: 2
    Last Post: 08-18-2008, 07:50 PM
  4. select with time out zero (in Linux? in Windows?)
    By mynickmynick in forum C Programming
    Replies: 9
    Last Post: 08-12-2008, 08:25 AM
  5. Displaying Function Run Time
    By pf732k3 in forum C Programming
    Replies: 1
    Last Post: 03-21-2008, 12:36 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21