|
![]() | 作者: wf88812 [wf88812]
![]() |
登录 |
time()函数原型:time_t time(time_t *timer) clock()函数原型:clock_t clock(void) clock()函数的功能是计时功能(系统内部计时器为18.2次/秒) 例如: #include "time.h" #include "stdio.h" #include "dos.h" main() { clock_t start,end; int i; start=clock(); /*开始计时*/ delay(2000); /*暂停2秒*/ end=clock(); /*计时结束*/ printf("\1: The different is %6.3f\n",(double)(end-start)/CLK_TCK); getch(); } 程序得到的时间值却不是两秒,而end-start是计数值,他除18.2应该得到2秒. 请问这是怎么回事? [此贴被 失落的枫(wf88812) 在 12月24日16时16分 编辑过] |
地主 发表时间: 04-12-24 00:07 |
![]() | 回复: wf88812 [wf88812] ![]() |
登录 |
我认为是delay()函数的问题,我实验过delay(2000)并没有暂停两秒,而是2/18.2秒.而且不管参数多大,甚至是0,它暂停的秒数依然是2/18.2秒. 实在搞不清这个函数到底是怎样实现的? |
B1层 发表时间: 04-12-24 16:21 |
![]() | 回复: haozsb [haozsb] ![]() |
登录 |
我编译过了,结果是0。11,但我还是看不出是哪出的错,真不好意思! |
B2层 发表时间: 04-12-27 23:35 |
![]() | 回复: wf88812 [wf88812] ![]() |
登录 |
多谢了,不知道那位朋友知道原因! |
B3层 发表时间: 05-01-03 11:40 |
![]() | 回复: hongliubo1 [hongliubo1] ![]() |
登录 |
#include "time.h" #include "stdio.h" #include "dos.h" main() { clock_t start,end; int i; start=clock(); /*开始计时*/ delay(2000); /*暂停2秒*/ end=clock(); /*计时结束*/ printf("\1: The different is %6.3f\n",(double)(end-start)/CLK_TCK); getch(); 0.11? |
B4层 发表时间: 05-01-05 10:15 |
![]() | 回复: galaxy112 [galaxy112] ![]() |
登录 |
delay()函数延迟时间与CPU的速度有关,速度慢的CPU延迟是准确的。 下面是一个延迟半秒的函数,可以试一下: void yanshi() { int jicunqi0,jicunqi1; union REGS in,out; in.h.ah=0x2c; intdos(&in,&out); jicunqi0=out.h.dl; while(1) { in.h.ah=0x2c; intdos(&in,&out); jicunqi1=out.h.dl; if(((jicunqi1-50)>=jicunqi0)||((jicunqi1<jicunqi0)&&((jicunqi1+50)>=jicunqi0))) break; } } |
B5层 发表时间: 05-01-05 11:05 |
|
20CN网络安全小组版权所有
Copyright © 2000-2010 20CN Security Group. All Rights Reserved.
论坛程序编写:NetDemon
粤ICP备05087286号