File: util.c

package info (click to toggle)
tcng 10b-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 3,632 kB
  • ctags: 2,515
  • sloc: ansic: 19,038; pascal: 4,640; yacc: 2,619; sh: 1,908; perl: 1,546; lex: 772; makefile: 755
file content (53 lines) | stat: -rw-r--r-- 994 bytes parent folder | download | duplicates (5)
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;
}