On 12/1/05, Andrew Paprocki <[EMAIL PROTECTED]> wrote:
> Is there a standard way that math operations should be performed using
> hrtime_t
> types if the compiler/platform defines longlong_t (from sys/types.h) to be a
> union?
>
> typedef union {
> double _d;
> int32_t _l[2];
> } longlong_t;
>
longlong_t ?
hmmm .. I'll have to try that with GCC just to see what happens.
Personally I use the hrtime_t as defined in the standard header files
as well as Sun ONE Studio 8 :
bash-3.00$ cat simp.c
/**************************************************************************
* Author : Dennis M. Clarke [EMAIL PROTECTED]
* Date : 1 December 2005
* Intent : Simple Timer test with the high res timer funcs.
* Detail : Take the example from the gethrtime (3C) manpage and make
* it actually work.
*
* compile with Sun ONE Studio 8 thus :
*
* $ cc -c -xO3 -xildoff -xstrconst -xarch=v9a -o simp.o simp.c
* $ cc -xO3 -xildoff -xstrconst -xarch=v9a -o simp simp.o
*
**************************************************************************/
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
int main (int argc, char *argv[]) {
hrtime_t start_hrt, end_hrt; /* process timer */
pid_t pid;
long int iteration_count;
int i;
start_hrt = gethrtime();
if ( start_hrt == -1 ) /* I have no idea what error condition may occur */
perror("Could not get high resolution starting time");
else {
iteration_count = 100;
for (i = 0; i < iteration_count; i++)
pid = getpid();
end_hrt = gethrtime();
printf("Avg getpid() time = %lld nsec\n",
(end_hrt - start_hrt) / iteration_count);
}
return(0);
} /* End of main */
bash-3.00$ cc -c -xO3 -xildoff -xstrconst -xarch=v9a -o simp.o simp.c
bash-3.00$ cc -xO3 -xildoff -xstrconst -xarch=v9a -o simp simp.o
bash-3.00$ ./simp
Avg getpid() time = 3334 nsec
bash-3.00$ ./simp
Avg getpid() time = 3432 nsec
bash-3.00$
I'll try this with GCC just to see what happens.
bash-3.00$
PATH=/opt/csw/gcc3/bin:/opt/csw/bin:/opt/csw/sbin:/usr/sbin:/usr/bin:/usr/dt/bin:/usr/openwin/bin:/usr/ccs/bin;export
PATH
bash-3.00$ ls
simp simp.c simp.o
bash-3.00$ gcc -c -o simp_gcc.o simp.c
bash-3.00$ gcc -o simp_gcc simp_gcc.o
bash-3.00$ ./simp_gcc
Avg getpid() time = 3428 nsec
bash-3.00$ ./simp_gcc
Avg getpid() time = 3343 nsec
bash-3.00$ ./simp_gcc
Avg getpid() time = 3389 nsec
bash-3.00$
I'm probably missing the point.
Now I need to use :
> typedef union {
> double _d;
> int32_t _l[2];
> } longlong_t;
and have another go at it ?
Dennis
_______________________________________________
opensolaris-code mailing list
[email protected]
https://opensolaris.org:444/mailman/listinfo/opensolaris-code