473,378 Members | 1,209 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

timer in milliseconds


hello,

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.

My problem is i want test the performance of ipsec, so i need the
time in milliseconds, how long it takes to connect to another host
over ipsec.

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
connect takes about 2 seconds (i test this with a sniffer) .

is the any way to get the time in milliseconds ????

thanks a lot and best regards, stefan
--
Posted via http://dbforums.com
Nov 13 '05 #1
11 14500
In <35****************@dbforums.com> S_at_work <me*********@dbforums.com> writes:

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 ????


If you're on a Unix platform and if microseconds are good enough, check
gettimeofday(2).

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 13 '05 #2

"S_at_work" <me*********@dbforums.com> wrote in message
news:35****************@dbforums.com...
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.


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
Nov 13 '05 #3
Da*****@cern.ch (Dan Pop) writes:
In <35****************@dbforums.com> S_at_work
<me*********@dbforums.com> writes:

[...]
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?


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"
Nov 13 '05 #4
In article <shenb.42505$Tr4.87514@attbi_s03>, ga*@ugcs.caltech.edu says...
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.


Please don't post this OT stuff, especially since it is likely to result
in bad results. For example, the solution using rdtsc for x86 is horribly
broken on SMP systems.

--
Randy Howard _o
2reply remove FOOBAR \<,
______________________()/ ()______________________________________________
SCO Spam-magnet: po********@sco.com
Nov 13 '05 #5

"Randy Howard" <ra**********@FOOmegapathdslBAR.net> wrote in message
news:MP************************@news.megapathdsl.n et...
In article <shenb.42505$Tr4.87514@attbi_s03>, ga*@ugcs.caltech.edu says...
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.


Please don't post this OT stuff, especially since it is likely to result
in bad results. For example, the solution using rdtsc for x86 is horribly
broken on SMP systems.


Certainly it us up to the user to understand the system in use.

I have used rdtsc on a SMP system, without considering the problems that it
might cause. As well as I remember it, it worked fine, but I can see that
it could cause problems. I think the results will still be better than
clock(), though.

-- glen
Nov 13 '05 #6

thanks for help now it works

here is the code



#include <stdio.h>

#include <time.h>

#define MAIN

//#define DEBUG

float GetTimeDelta(struct timeval *time1){

float timereturn;

struct timeval time2;

time2.tv_usec=0;

time2.tv_sec=0;

if(time1->tv_usec==NULL&&time1->tv_sec==NULL ){

timereturn = 0.0;

gettimeofday(time1,NULL);

}

else{

gettimeofday(&time2,NULL);

if(time1->tv_usec > time2.tv_usec){

timereturn =((1000000.0+(time2.tv_usec-time1-
tv_usec))/1000000.0);


time2.tv_sec-=1;

// printf(" milliseconds 1>2:%f\n",timereturn);

}

else{

timereturn =(time2.tv_usec-time1->tv_usec)/1000000.0;

//printf(" milliseconds 2>1:%f\n",timereturn);

}

timereturn+=(time2.tv_sec -time1->tv_sec);

}

#ifdef DEBUG

printf("time1 seconds:%d\n",time1->tv_sec);

printf("time1 milliseconds:%d\n",time1->tv_usec);

printf("time2 seconds:%d\n",time2.tv_sec);

printf("time2 milliseconds:%d\n",time2.tv_usec);

return timereturn;

#endif DEBUG

}

#ifdef MAIN

int main()

{

struct timeval time;

time.tv_sec =0;

time.tv_usec=0;

int i=100000;

int a=0;

printf("start time %f\n",GetTimeDelta(&time));

//time consuming

sleep(4);

while(i--)

a= i%12;

//end time consuming

printf("end time %f\n",GetTimeDelta(&time));

}

#endif
--
Posted via http://dbforums.com
Nov 13 '05 #7
In <2Unnb.46121$Tr4.103510@attbi_s03> "Glen Herrmannsfeldt" <ga*@ugcs.caltech.edu> writes:

"Randy Howard" <ra**********@FOOmegapathdslBAR.net> wrote in message
news:MP************************@news.megapathdsl. net...
In article <shenb.42505$Tr4.87514@attbi_s03>, ga*@ugcs.caltech.edu says...
> 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 theclock > rate, though.)
>
> It takes a two instruction assembly program on x86 (off topic) , for
> example.


Please don't post this OT stuff, especially since it is likely to result
in bad results. For example, the solution using rdtsc for x86 is horribly
broken on SMP systems.


Certainly it us up to the user to understand the system in use.

I have used rdtsc on a SMP system, without considering the problems that it
might cause. As well as I remember it, it worked fine, but I can see that
it could cause problems. I think the results will still be better than
clock(), though.


If the solution has to be platform-specific, anyway, why not use a *clean*
solution provided by the implementation, as an extension? Especially
since the OP only needs millisecond resolution.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 13 '05 #8
In <35****************@dbforums.com> S_at_work <me*********@dbforums.com> writes:

thanks for help now it works

here is the code


Why did you feel compelled to post non-portable C code to this newsgroup?

BTW, the *correct* usage of gettimeofday requires the inclusion of
<sys/time.h>.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 13 '05 #9
In article <2Unnb.46121$Tr4.103510@attbi_s03>, ga*@ugcs.caltech.edu
says...
Certainly it us up to the user to understand the system in use.
Absolutely.
I have used rdtsc on a SMP system, without considering the problems that it
might cause. As well as I remember it, it worked fine, but I can see that
it could cause problems.


The problem is that the tsc data is not synched between CPUs, meaning that
your results are only accurate as long as your process (or thread) is
pinned to a specific CPU. That's usually not the case (nor ideal).
--
Randy Howard _o
2reply remove FOOBAR \<,
______________________()/ ()______________________________________________
SCO Spam-magnet: po********@sco.com
Nov 13 '05 #10

"Randy Howard" <ra**********@FOOmegapathdslBAR.net> wrote in message
news:MP************************@news.megapathdsl.n et...
In article <2Unnb.46121$Tr4.103510@attbi_s03>, ga*@ugcs.caltech.edu
says...
Certainly it us up to the user to understand the system in use.


Absolutely.
I have used rdtsc on a SMP system, without considering the problems that it might cause. As well as I remember it, it worked fine, but I can see that it could cause problems.


The problem is that the tsc data is not synched between CPUs, meaning that
your results are only accurate as long as your process (or thread) is
pinned to a specific CPU. That's usually not the case (nor ideal).


I have a post to comp.sys.intel to see if anyone there knows. I know TSC
is zero at reset, and if all leave reset at the same time, they may be
synchronized. I will see if anyone answers there.

The one time I did it on a four way SMP machine was in Java, using a JVM
native method, which means C. I took a simple C program, compiled it
with -S, modified the result with an RDTSC instruction, assembled it, and it
pretty much worked. I didn't need nanosecond resolution, but millisecond
may not have been good enough. There are enough problems with the way Java
native method calls not to worry too much about the SMP problem.

I will see what they say on comp.sys.intel, though. I have a dual 350MHz P2
system at home, but I never tried it on that one.

-- glen
Nov 13 '05 #11
In article <hyAnb.51086$Tr4.105803@attbi_s03>, ga*@ugcs.caltech.edu
says...
The problem is that the tsc data is not synched between CPUs, meaning that
your results are only accurate as long as your process (or thread) is
pinned to a specific CPU. That's usually not the case (nor ideal).


I have a post to comp.sys.intel to see if anyone there knows. I know TSC
is zero at reset, and if all leave reset at the same time, they may be
synchronized. I will see if anyone answers there.


Been there done that. The folks I asked at Intel admit that is the case.
It's probably documented as such formally. I believe it was discussed
recently on the threading forum at Intel's website and verified as
unreliable" by Intel employees there. It has certainly been discussed in
plenty of places. Please let me know if you get a different answer, but I
have seen it give erratic results (I.e. negative tsc differences inside of
wraparound times) due to TSC skew between processors. You may need to
have a lot of dynamic load on the box such that the scheduler is moving
processes around between CPUs before it becomes obvious.

--
Randy Howard _o
2reply remove FOOBAR \<,
______________________()/ ()______________________________________________
SCO Spam-magnet: po********@sco.com
Nov 13 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: laurenq uantrell | last post by:
I have been using the following function to test the speed of various functions, however, quite often the return value is zero. I'm hoping someone can help improve on this. Function TimeIt() As...
5
by: Jeroen CEuppens | last post by:
Hi, I want to have a timer that counts how long it takes to draw 2 bitmap files...... I use the compact framework, so I haven't got System.Timers Please help me... Greetz JC
9
by: HL | last post by:
I am using VS 2005 Beta - C# Problem: The Timer fires a few milliseconds before the actual Due-Time Let's say a timer is created in the following manner: System.Threading.Timer m_timer = null;...
7
by: Noozer | last post by:
I have a timer on a form. It isn't firing at all. I know that the timer is enabled, and that the interval is low (4000, which should be 4 seconds). To ensure the timer wasn't being inadvertantly...
11
by: Philip Wagenaar | last post by:
Hello, I am using a timer object in my Windows Forms Application. Does the code in ..elapsed event run in a diffrent thread? If the interval is set to 10 milliseconds and the time to execute the...
9
by: martin1 | last post by:
Hi, All, My question is how to set up timer start 15 sec past minute. It always start 15 sec past minute. For example, if current time is 8:30:45, the timer starts on 8:31:15 am; if current...
10
by: igor | last post by:
I have recently discovered that the system.Timers.Timer from.Net Framework v1.1 is not reliable when used on Windows 2003 server. When incorporated into a Windows Service, the timer_elapsed event...
8
jeffbroodwar
by: jeffbroodwar | last post by:
please help me get the system's time (with milliseconds) i need it to calculate the Soap request and response time in my SOAP project. i tried to use timer but the problem is, whenever i'm invoking a...
1
by: =?Utf-8?B?Q2hyaXM=?= | last post by:
1. What is a difference between System.Windows.Forms.Timer and System.Threading.Timer ? 2. How does it work? How is elpasing time counted? I.e interval is set to 10ms and a timer starts working -...
3
missshaikh
by: missshaikh | last post by:
Hi all, i need the count down timer when button click the timer start and count down work on ASP.net :( i have one timer which is on JavaScript that run page onload . but i need the Button...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.