計算的時間跨度,我會盡量簡短:用C
我想衡量這樣的小東西在C時間跨度,因爲這在發送插槽:
sendto (s, buffer, sizeof (buffer), 0, (struct sockaddr *) &peer, peerlen);
目前,我正在做這個:
clock_t cBegin = (double)clock() * CLOCKS_PER_SEC;
sendto (s, buffer, sizeof (buffer), 0, (struct sockaddr *) &peer, peerlen);
clock_t cEnd = (double) clock() * CLOCKS_PER_SEC;
elapTicks = cEnd - cBegin;
elapMilli = elapTicks/1000;
printf ("Milisegundos: %lf, %lf\n", cBegin, cEnd);
但我的printf總是0.000000。我應該如何繼續?
在此先感謝!
你的問題之一是你應該用* CLOCKS_PER_SEC分隔*而不是乘。 – dreamlax 2012-04-27 00:17:36