Thread: Basic C Programs Starting Up Slowly

  1. #1
    Registered User
    Join Date
    Jan 2014
    Posts
    16

    Basic C Programs Starting Up Slowly

    Hey guys,

    I am not sure if this is the right place to ask about compilers and C, so if it's not, I am sorry.

    I am just starting out learning C and I am using MinGW, Widnows 7, and cmd.exe.

    I am starting from scratch and learning very short and simple programs, like 20 lines long.


    After I use MinGW (gcc) to compile, the programs start up rather slowly, sometimes up to about 3-5 seconds. One with a big nested loop even took about 15 seconds to load. After they run once, the next time they run, it's instant.

    Last time I learned from this book, I don't remember them starting so slowly. I use the command "gcc sample.c -o sample".


    It just concerns me that these tiny little programs are starting up so slowly. I'm scared it's a problem with my computer or MinGW installation. When I start making more advanced programs, I don't want them running slower than they ought to be.


    Let me know if you can help and/or need any further information.

    Again, if this is not the right forum for this question, my apologies.


    Thanks,

    Ryan
    Last edited by ryant324; 02-03-2014 at 02:00 PM.

  2. #2
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,907
    Well, we can't determine if it's a problem with the program, unless you post the code. But I don't really think we need it in this case.

    Have you tried it with GCC, to compare to MinGW? I would do that for sure, see if the compiler/environment/platform makes a difference. Also, perhaps try another free compiler on Windows, like Pelles C or MSVC++ (not my favorite, but good for comparison). Both are free.

    Most likely though, is that the executable is non cached immediately after you compile it. Perhaps the standard C runtime library (for things like printf, malloc, fopen, etc) MinGW uses is also not cached. Thus, the first time your program runs, it must load the runtime library, as well as your program. Subsequent runs of your program will find the runtime library cached and thus only need to load your tiny program.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,968
    Still not learning the cross-posting lesson I see.
    Simple C Programs Running Slowly after Compilation - Dev Shed
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Jan 2014
    Posts
    16
    Quote Originally Posted by Salem View Post
    Still not learning the cross-posting lesson I see.
    Simple C Programs Running Slowly after Compilation - Dev Shed
    I'm sorry? I know of no cross-posting lesson.

    Am I not supposed to post on both of these forums? Are they related? I figured that I joined two different forums and have access to two sets of users.

    Please inform me.

    edit: and your wording suggests that I was warned of this before, as I am "still not learning." It would have been much more helpful if you would have just told me what I did wrong and the reason for the rule.
    Last edited by ryant324; 02-03-2014 at 03:42 PM.

  5. #5
    Registered User
    Join Date
    Jan 2014
    Posts
    16
    Quote Originally Posted by anduril462 View Post
    Well, we can't determine if it's a problem with the program, unless you post the code. But I don't really think we need it in this case.

    Have you tried it with GCC, to compare to MinGW? I would do that for sure, see if the compiler/environment/platform makes a difference. Also, perhaps try another free compiler on Windows, like Pelles C or MSVC++ (not my favorite, but good for comparison). Both are free.

    Most likely though, is that the executable is non cached immediately after you compile it. Perhaps the standard C runtime library (for things like printf, malloc, fopen, etc) MinGW uses is also not cached. Thus, the first time your program runs, it must load the runtime library, as well as your program. Subsequent runs of your program will find the runtime library cached and thus only need to load your tiny program.
    Is the GCC the GNU one?

  6. #6
    Registered User
    Join Date
    Jan 2014
    Posts
    16
    This is the most recent practice problem I have done. It took 26 seconds before the program ran for the first time after compiling. I understand it is a long set of loops, but 26 seconds just sounds wrong. I have done this book before on a different computer, and I'm pretty sure this program didn't take 26 seconds before it ran on it's first try.


    The other programs that don't involve such involved loops take a lot less time, but a lot of them still take longer than I expect.


    Note that if I run it again, it runs instantly.


    Code:
    #include <stdio.h>
    
    
    int main()
    {
        char a,b,c,d,e;
    
    
        for(a='A';a<='Z';a=a+1)
            for(b='A';b<='Z';b=b+1)
                for(c='A';c<='Z';c=c+1)
                    for(d='A';d<='Z';d=d+1)
                        for(e='A';e<='Z';e=e+1)
                            printf("%c%c%c%c%c\t",a,b,c,d,e);
    
    
        return 0;
    }

  7. #7
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Check these:

    The BIOS and/or Windows 7, is set to save energy. I have an overclocked i7 that is almost unusable if it's set to run on the default settings.

    Change that to "high performance", mode, with the HD never sleeping, and all of a sudden it's quite fast. Be sure to change both settings in the BIOS, AND the ones in Windows 7.

    A buddy of mine had a laptop that had this exact problem, also. Changing the power settings made all the difference.

    It runs instantly the next time, because you haven't given it time to put itself back to sleep (it has a delay).

    The program compiles and runs instantly in Pelles C, on Windows 7 OS. Because of all the printing, it takes it a long time to finish running, of course.
    Last edited by Adak; 02-03-2014 at 04:01 PM.

  8. #8
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,907
    Quote Originally Posted by ryant324 View Post
    I'm sorry? I know of no cross-posting lesson.

    Am I not supposed to post on both of these forums? Are they related? I figured that I joined two different forums and have access to two sets of users.

    Please inform me.

    edit: and your wording suggests that I was warned of this before, as I am "still not learning." It would have been much more helpful if you would have just told me what I did wrong and the reason for the rule.
    Cross-posting (posting to multiple forums) is considered bad etiquette. Effectively, you are being selfish with and inconsiderate of our time. I understand this may not be your intention, but this is how it is often perceived, and the effect is the same. People over at Dev Shed or wherever, may be busy working on answering your question there, when you've already received an answer here. We help people out for free, in our spare time. We have jobs, families, hobbies of our own, etc, etc, and if we answer a question that is already answered, two things happen. First, we are not spending time on somebody else's answer, since we're busy duplicating (read: wasting) our effort on yours. Second, if we knew you were already getting help, we might prefer to spend our time on something else.

    Now, there are a few instances where it is acceptable to cross post, and there are right ways to do it. Usually this is when you have a very esoteric, multi-discipline problem, where there simply would not be sufficient expertise on any one forum. The correct way to handle this is, on each forum you are seeking help, to note that you have cross-posted, why you have done so, and to link to each cross-posted forum, so that people assisting you can stay apprised of the progress, and wont duplicate effort. Your situation does not apply, however.

    What really irks me, personally, beyond the above, is that cross-posting is explicitly forbidden in our forum guidelines. When you signed up for an account on this forum, you agreed to having read the rules, having understood them, and having agreed to abide by them. Could you imagine telling a police officer you didn't know there was such a thing as a speed limit, or that red lights mean stop? That would be absurd. Just like it's absurd for you to state that you have no idea cross posting is wrong.

    All this, on top of the fact that in your first thread over at Dev Shed (link), Salem referred you to a wonderful site on forum etiquette (that would be the catb.org link), that you apparently ignored. It clearly discusses why cross-posting is wrong. Just so you have it again: How To Ask Questions The Smart Way. Read it this time.

  9. #9
    Registered User
    Join Date
    Jan 2014
    Posts
    16
    Quote Originally Posted by anduril462 View Post
    All this, on top of the fact that in your first thread over at Dev Shed (link), Salem referred you to a wonderful site on forum etiquette (that would be the catb.org link), that you apparently ignored. It clearly discusses why cross-posting is wrong. Just so you have it again: How To Ask Questions The Smart Way. Read it this time.
    I'm sorry, I didn't know about this. I just thought that putting my question in multiple places would increase the likelihood of it getting answered.

    And I totally missed the "Here, read this" link that linked to a huge article with no explanation as to why he referred me to that link. Come on Salem, you could be a little more descriptive and informative: even just a little bit more so.

    But again, my apologies for not knowing about the rules.

  10. #10
    Registered User
    Join Date
    Jan 2014
    Posts
    16
    Quote Originally Posted by Adak View Post
    Check these:

    The BIOS and/or Windows 7, is set to save energy. I have an overclocked i7 that is almost unusable if it's set to run on the default settings.

    Change that to "high performance", mode, with the HD never sleeping, and all of a sudden it's quite fast. Be sure to change both settings in the BIOS, AND the ones in Windows 7.

    A buddy of mine had a laptop that had this exact problem, also. Changing the power settings made all the difference.

    It runs instantly the next time, because you haven't given it time to put itself back to sleep (it has a delay).

    The program compiles and runs instantly in Pelles C, on Windows 7 OS. Because of all the printing, it takes it a long time to finish running, of course.
    If this was the problem, would that mean it would take 26 seconds to load an an end user's machine who does not have their settings changed?

  11. #11
    Registered User
    Join Date
    Jan 2014
    Posts
    16
    I told the guys on the other forums to stop posting, but they didn't.

    They told me it might be my antivirus evaluating the program, and they were right.

    When I turn my anti-virus off and recompile, the program fires up instantly.

  12. #12
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,750
    Quote Originally Posted by ryant324 View Post
    I told the guys on the other forums to stop posting, but they didn't.
    That's one of the best comments I've seen on this forum. Kudos to you! =D

  13. #13
    Registered User
    Join Date
    Jan 2014
    Posts
    16
    We are working on my issues on a different forum. Thanks for the help guys.

    By the way, if anyone runs across this problem, it is due to my Kaspersky Internet Security 2014. We are still trying to figure out if there is a fix.

    Simple C Programs Running Slowly after Compilation - Dev Shed

    Excluding a Folder from Real-Time Scanning - Kaspersky Lab Forum

    Thanks again guys.

    --Ryan

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 12-26-2013, 12:31 PM
  2. Making DLL for other programs(Basic question)
    By ilerleartik in forum C Programming
    Replies: 3
    Last Post: 03-26-2012, 06:47 AM
  3. Starting programs
    By Molokai in forum C Programming
    Replies: 1
    Last Post: 04-16-2009, 10:10 AM
  4. Replies: 10
    Last Post: 11-23-2007, 12:13 AM
  5. Starting Programs
    By CumQuaT in forum Windows Programming
    Replies: 5
    Last Post: 11-17-2003, 04:47 AM