我在网上搜索过,但我只找到了一个办法,但以这种方式它返回的秒数而不是毫秒。如何获得以毫秒为单位的C所花费的时间? (Windows)
我的代码是:
#include <stdio.h>
#include <assert.h>
#include <time.h>
int main(void)
{
int solucion;
time_t start, stop;
clock_t ticks;
long count;
time(&start);
solucion = divisores_it(92000000, 2);
time(&stop);
printf("Finnished in %f seconds. \n", difftime(stop, start));
return 0;
}
根据http://man7.org/linux/man-pages/man3/ftime.3.html,ftime()已过时。也许更好的跨平台解决方案是使用['std :: chrono'](http://en.cppreference.com/w/cpp/chrono)库。 – erobertc
@erobertc OP需要一个'C'解决方案,而不是'C++'。你的建议需要'C++'。 – rbaleksandar