1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
/*
* util.c - Utility functions
*
* Written 2001,2002 by Werner Almesberger
* Copyright 2001 EPFL-ICA
* Copyright 2001,2002 Bivio Networks, Network Robots
*/
#include <stdio.h>
#include <sys/time.h>
#include "util.h"
/* ----- Helper functions for performance tuning --------------------------- */
static struct timeval timer;
void start_timer(void)
{
gettimeofday(&timer,NULL);
}
void print_timer(const char *label)
{
struct timeval now;
gettimeofday(&now,NULL);
now.tv_usec -= timer.tv_usec;
now.tv_sec -= timer.tv_sec;
if (now.tv_usec < 0) {
now.tv_usec += 1000000;
now.tv_sec--;
}
fprintf(stderr,"%s: %d.%06d\n",label,(int) now.tv_sec,(int) now.tv_usec);
}
/* ----- Helper function for qsort ----------------------------------------- */
int comp_int(const void *a,const void *b)
{
/*
* These numbers are small (16 bit), so we don't need to worry about
* overflows.
*/
return *(const int *) a-*(const int *) b;
}
|