1

I have an extremely small project in visual studio 2012 (only 50 lines of code). I only have one source file (main.cpp). But yet it takes about 20 seconds or more to compile! How am I supposed to speed it up? When I use C# the compile times are fast but when it comes to C++ it's super slow.

As for my minimal computer specs, I have an i5 processor, 4gb of ram and it is a quad core. It shouldn't be taking this long to compile something that is only 50 lines long. What should I do?

My Code:

    #include<iostream>
using namespace std;

class Entity
{
protected: 
    int health; 
public: 
    void SetHealth(int value)
    {
        health = value;
    }

    void DisplayHealth()
    {
        cout << "Entity: " << health << endl;
    }
};

class Player : public Entity
{
private:
    int xp;
public: 
    void DisplayHealth()
    {
        cout << "Player: " << health << endl;
    }
};

class Enemy : public Entity
{

};

int main()
{
    Player player; 

    Entity *entity = &player;

    entity->SetHealth(10); 
    player.DisplayHealth();

    system("pause");
    return 0;
}
ildjarn
  • 62,044
  • 9
  • 127
  • 211
CodingMadeEasy
  • 2,257
  • 4
  • 19
  • 31
  • 6
    Depends a lot on what your 50 lines pulls in. What #includes do you have? – Joe Oct 24 '12 at 20:42
  • If it's only 50 lines could you show them to us? – halex Oct 24 '12 at 20:43
  • Apart from what @Joe said, check your optimization settings as well. `Configuration Properties -> C/C++ -> Optimization`. – Mahesh Oct 24 '12 at 20:43
  • 2
    Use `cl /P file.preprocessed.cpp your.source.file.cpp` (from MSVS console) to see how many lines of code `cl` _actually_ have to compile – Lol4t0 Oct 24 '12 at 20:44
  • The 20 seconds you are referring to sounds like spin-up time to me. At any rate, [this article](http://blogs.msdn.com/b/vcblog/archive/2012/05/24/10309971.aspx) seems very thorough about the subject. – Robert Harvey Oct 24 '12 at 20:44
  • Did you make use of `stdafx.h` to get your headers precompiled? – Joachim Isaksson Oct 24 '12 at 20:48
  • I have added in my code. It's nothing trivial. – CodingMadeEasy Oct 24 '12 at 20:48
  • Turn on output the preprocess to a file under Properiteies/C/C++/Preprocessor after it builds look in your project directory for a .i file that is what the compiler is looking out it will be about 200K lines – rerun Oct 24 '12 at 20:48
  • 1
    What project type are you using? Compile of your sample program in a Win32 console project in VS2012 on an old Macbook Pro, less than 2 seconds with no warmup, second time less than a second (16GB and an SSD though) – Joachim Isaksson Oct 24 '12 at 20:53
  • So, 1. attach comilation log. 2. try to compile this project by hands in console using `cl test.cpp`. Does it still takes a lot of time? 3. Does your disc read speed is ok? – Lol4t0 Oct 25 '12 at 08:06

1 Answers1

0

The code is not using anything that can make the compiler sweat.

Some options that might hold up performance: clear %localappdata%\Microsoft\WebSiteCache Also clear out %localappdata%\temp folder.

Unplug your n/w cable and try (or turn of wireless connection).

Also in tools\options\debugging: disable edit and continue. you might be generating MAP, PDB etc... See what you need and what you don't.

Some people have reported that turning of "hardware acceleration' helps (options)!

Check your PCH (pre compiled header file) and see if it has grown too big.

Allow incremental linking so that everthing is not being built all the time.

Also, ensure that the disk is not fragmented.