Next Spaceship

Driving into future...

How to Record Time in C++?

| Comments

To record the time your program costs, you can use the function clock(), that is defined in <ctime>. Here is an example showing how to use this function:

``` cpp How To Record Time #include #include using namespace std; int main() { clock_t t1, t2; t1 = clock(); int i, s = 0; for (i = 0; i < 100000000; i++) s += i; t2 = clock(); printf("%fn", (double)(t2 - t1) / CLOCKS_PER_SEC); return 0; }