Run the time command on your program :
/usr/bin/time ./MyProgram
| // MACRO | |
| #include <time.h> | |
| #ifndef SYSOUT_F | |
| #define SYSOUT_F(f, ...) _RPT1( 0, f, __VA_ARGS__ ) // For Visual studio | |
| #endif | |
| #ifndef speedtest | |
| #define speedtest(data) for (long blockTime = NULL; (blockTime == NULL ? (blockTime = clock()) != NULL : false); SYSOUT_F(data "%.9fs", (double) (clock() - blockTime) / CLOCKS_PER_SEC)) | |
| #endif | |
| // USAGE | |
| speedtest("Block Speed: ") | |
| { | |
| // The code goes here | |
| } | |
| // OUTPUT | |
| // Block Speed: 0.127000000s |
| #include <iostream> | |
| #include <time.h> | |
| void printTimeSince(clock_t tStart); | |
| int main(void) { | |
| clock_t tStart = clock(); | |
| /* Do your stuff here */ | |
| printf("Time taken: %.2fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC); | |
| return 0; | |
| } | |
| void printTimeSince(clock_t tStart) | |
| { | |
| printf("Time taken: %.2fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC); | |
| } |