测量C运行时间的代码,运行花费记录进上面的日志文件中。
<br />
/* Subtracts time values to determine run time */<br />
int timeval_subtract (struct timeval *result, struct timeval *t2, struct timeval *t1)<br />
{<br />
long int diff = (t2->tv_usec + 100000 * t2->tv_sec) - (t1->tv_usec + 100000 * t1->tv_sec);</p>
<p> result->tv_sec = diff / 100000;<br />
result->tv_usec = diff % 100000;</p>
<p> return (diff < 0);<br />
}</p>
<p>/* Starts timer */<br />
void tic (struct timeval *timer) {<br />
gettimeofday (timer, NULL);<br />
}</p>
<p>/* Stops timer and prints difference to the screen */<br />
void toc (struct timeval *timer) {<br />
struct timeval tv_end, tv_diff;</p>
<p> gettimeofday (&tv_end, NULL);<br />
timeval_subtract (&tv_diff, &tv_end, timer);<br />
ndebug("running time is %ld.%06ld\n", tv_diff.tv_sec, tv_diff.tv_usec);</p>
<p>}</p>
<p>//calling tic(&timer) first , running issue, calling toc(&timer) @ the end.<br />
</p>
从这里直到第一楼,M$上系统不包调通