计时器,以毫秒为单位 [英] timer in milliseconds

查看:181
本文介绍了计时器,以毫秒为单位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



你好,


任何人都可以给我一段代码,或者一个提示,我怎么能收到

我需要连接()到另一台主机的时间,以毫秒为单位。


我的问题是我想测试ipsec的性能,所以我需要

时间以毫秒为单位,连接到另一台主机需要多长时间

超过ipsec。


1)我试过clock()但是clock()不要工作,因为connect()不使用

cpu时间就像sleep(),所以我总是得到0毫秒,但

连接大约需要2秒钟(我用嗅探器测试这个。


是以毫秒为单位获得时间的任何方式????


非常感谢问候,stefan

-

发表于 http:/ /dbforums.com

推荐答案

在< 35 **************** @ dbforums.com> S_at_work< me ********* @ dbforums.com>写道:

In <35****************@dbforums.com> S_at_work <me*********@dbforums.com> writes:

任何人都可以给我一段代码或提示,我怎样才能收到连接()到另一台主机所需的时间以毫秒为单位。


如果你把这个问题发布到一个专门用于你的平台的b / b
编程的新闻组,我有理由相信有人可以。没有便携式的

解决方案来解决你的问题,你可以从标准C获得最好的

测量实时间隔是时间(),它通常适用于

秒的分辨率,比你需要的b $ b b差三个数量级。

1)我试过clock()但是clock()不要工作,因为connect()不使用像sleep()那样的cpu时间,所以我总是得到0毫秒,但是


你在哪里得到的想法sleep()使用CPU时间?

connect大约需要2秒钟(我用嗅探器测试)。


是的,忘掉时钟(),它不是你需要的,无论是否有任何分析问题:它不测量实时间隔。

是以毫秒为单位获取时间的任何方式????
can anybody give me a piece of code , or a hint , how i can recieve the
time i need for connect() to another host in milliseconds.
If you post this question to a newsgroup dedicated to programming on
your platform, I''m reasonably sure someone can. There is no portable
solution to your problem, the best you can get from standard C for
measuring real time intervals is time() and it typically works with
second resolution, i.e. three orders of magnitude worse than what you
need.
1) i tried clock() but clock() don''t work, because connect() don''t use
cpu time like sleep(), so i always get 0 milliseconds, but the
Where did you get the idea that sleep() uses CPU time from?
connect takes about 2 seconds (i test this with a sniffer) .
Yup, forget about clock(), it''s not what you need, regardless of any
resolution issues: it does NOT measure real time intervals.
is the any way to get the time in milliseconds ????




如果你在Unix平台上,如果微秒就够了,查看

gettimeofday(2)。


Dan

-

Dan Pop

DESY Zeuthen,RZ集团

电子邮件: Da ***** @ ifh.de




" S_at_work" <我********* @ dbforums.com>在消息中写道

news:35 **************** @ dbforums.com ...

"S_at_work" <me*********@dbforums.com> wrote in message
news:35****************@dbforums.com...
can任何人都给我一段代码或一个提示,我怎么能在几毫秒内收到connect()到另一台主机所需的时间。
can anybody give me a piece of code , or a hint , how i can recieve the
time i need for connect() to another host in milliseconds.




许多处理器现在都有一个计数时钟周期的寄存器。如果你的价格是b $ b,这可能会做你想要的。 (你还需要知道时钟

率。)


它需要x86上的两个指令汇编程序(非主题),用于

例子。


- glen



Many processors now have a register that counts clock cycles. If yours
does, this probably will do what you want. (You also need to know the clock
rate, though.)

It takes a two instruction assembly program on x86 (off topic) , for
example.

-- glen


Da ***** @ cern.ch (Dan Pop)写道:
Da*****@cern.ch (Dan Pop) writes:
In< 35 ******* *********@dbforums.com> S_at_work
< me ********* @ dbforums.com>写道:
In <35****************@dbforums.com> S_at_work
<me*********@dbforums.com> writes:



[...]


[...]

1)我试过clock()但是clock()不要工作,因为connect()不使用像sleep()那样的cpu时间,所以我总是得到0毫秒,但是
1) i tried clock() but clock() don''t work, because connect() don''t use
cpu time like sleep(), so i always get 0 milliseconds, but the



你在哪里得到的想法是sleep()使用CPU时间?



Where did you get the idea that sleep() uses CPU time from?




我认为他的意思是connect(),就像sleep()一样,不会占用CPU时间。

(它当然使用了一些,但还不足以使它有用来衡量

吧。)


-

Keith Thompson(The_Other_Keith) ks*@cts.com < http://www.ghoti.net/~kst>

圣地亚哥超级计算机中心< *> < http://www.sdsc.edu/~kst>

Schroedinger做莎士比亚:要*和*不要



I think he meant that connect(), like sleep(), doesn''t use CPU time.
(It uses some, of course, but not enough to make it useful to measure
it.)

--
Keith Thompson (The_Other_Keith) ks*@cts.com <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://www.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"


这篇关于计时器,以毫秒为单位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆