I'm doing command line compiling, and thought there might be some switch that would list starting and finishing time, but couldn't find anything. I'm using Windows, and trying to work with the default gcc/g++ from mingw installed with Code::Blocks. Or is there some way of doing this with some shell command? There's got to be a way?

Recommended Answers

All 4 Replies

This little program will launch your g++ compiler and time how long it took to compile the source. Update the compiler_path variable to reflect your system's configuration.

#include <iostream>
#include <ctime>
#include <string>
using namespace std;

int main(){
    string compiler_path = "c:\\mingw\\bin\\g++.exe";
    cout << "Enter the file to compile: ";
    string filename;
    cin >> filename;
    clock_t start = clock();
    system((compiler_path + ' ' + filename + " -o " + filename + ".exe").c_str());
    cout << "Compile time: " << (clock() - start) / float(CLOCKS_PER_SEC) << " seconds." << endl;
    return 0;    
}

The GCC compiler has this option built in, just compile with this option

-ftime-report

example:

g++ filename.cpp -ftime-report -o filename

The GCC compiler has this option built in [...]

What a neat feature!...and the G++ method is more accurate. To compile my silly little program, my own method reports an average of 0.82 sec versus G++'s report of 0.50 sec - maybe its in the system call. Thanks for the tip gerard!

Thanks guys! Just what I was looking for!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.