[Prev][Next][Index][Thread]

Re: measuring time (solution on UP x86)



On Tue, 13 Jun 2000, Vishal Zinjuvadia wrote :
> Hi 
> 
> 	I am carrying out some performance test and I need to measure the
> time required to perform read/write operation on oskit. I am using freebsd
> socket libraries. I tried linking loskit_posix library and using
> gettimeofday() but the granularity offered by it is very low and does not
> meet the requirements. Is there any way I can have time measured upto
> microseconds in oskit ?  I happened to come across a function fs_gettime()
> (described in section 9.7.6 of oskit doc) and wondered if I could use it.
> I didnot come across any use of this function in the examples directory in
> oskit distribution.

If you are working on a uniprocessor machine with x86 CPU where x >= 5,
you can use the assembly instruction rdtsc in a code like that :

unsigned long long t;

asm volatile
(
	"rdtsc"
	: "=A" (t)
);

It will give you in t a time measured in CPU cycles elapsed since the
bootup of the machine, if I don't mistake. So you can have time measured
in 2ns units if you have a 500MHz CPU for example. It is VERY precise,
useful and quick. Note that t is a 64 bit integer.

-- 
 (o-  Hi, I'm a deadly e-mail virus, please copy me into your .signature
 /\   file to help me spread. :: Bonjour, je suis un dangereux virus. SVP
Y_/_  copiez-moi dans votre fichier .signature pour m'aider à me propager.

References: