I have written a c++ program , I want to know how to calculate the time taken for execution so I won\'t exceed the time limit.
#include
usin
OVERVIEW
I have written a simple semantic hack for this using @AshutoshMehra
response. You code looks really readable this way!
MACRO
#include
#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