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?

7 Years
Discussion Span
Last Post by Frederick2

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



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

Edited by gerard4143: n/a


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!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.