diff wtime.c @ 0:0ce47c784647

Initial commit
author Merten Sach <msach@mailbox.tu-berlin.de>
date Tue, 27 Sep 2011 15:08:02 +0200
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/wtime.c	Tue Sep 27 15:08:02 2011 +0200
     1.3 @@ -0,0 +1,37 @@
     1.4 +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
     1.5 +/*   File:         wtime.c                                                   */
     1.6 +/*   Description:  a timer that reports the current wall time                */
     1.7 +/*                                                                           */
     1.8 +/*   Author:  Wei-keng Liao                                                  */
     1.9 +/*            ECE Department Northwestern University                         */
    1.10 +/*            email: wkliao@ece.northwestern.edu                             */
    1.11 +/*   Copyright, 2005, Wei-keng Liao                                          */
    1.12 +/*                                                                           */
    1.13 +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
    1.14 +
    1.15 +#include <sys/time.h>
    1.16 +#include <stdio.h>
    1.17 +#include <stdlib.h>
    1.18 +
    1.19 +/*
    1.20 +*	Function: wtime
    1.21 +*	---------------
    1.22 +*	Provides a millisecond-resolution timer for measurement purposes.
    1.23 +*/
    1.24 +double wtime(void) 
    1.25 +{
    1.26 +    double          now_time;
    1.27 +    struct timeval  etstart;
    1.28 +    struct timezone tzp;
    1.29 +
    1.30 +    if (gettimeofday(&etstart, &tzp) == -1) {
    1.31 +		fprintf(stderr, "Timing Error: Could Not Get Current Time\n");
    1.32 +		exit(EXIT_FAILURE);
    1.33 +	}
    1.34 +
    1.35 +    now_time = ((double)etstart.tv_sec) +              /* in seconds */
    1.36 +               ((double)etstart.tv_usec) / 1000000.0;  /* in microseconds */
    1.37 +    return now_time;
    1.38 +}
    1.39 +
    1.40 +