Clock/sample.c File Reference

Show timing example in both milliseconds and nanonseconds. Show the ability on Unix systems to time both using milliseconds and nanosecond timers. More...

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <sys/time.h>
#include <math.h>
#include "report.h"

Defines

#define R   5
 Number of rows to compute.
#define T   30
 For each row, the number of trials to execute.

Functions

char * buildRow (long n, long times[R][T])
 Build a row for the output by computing average and stdev after discarding the lowest and highest results.
void buildTable (long times[R][T])
long diffNanoTimer (struct timespec *before, struct timespec *after)
 Compute the difference between two time values in usecs.
int main (int argc, char **argv)
 Compute the addition of numbers in range 1,000,000 to 5,000,000 for a fixed number of trials.

Variables

long MStimes [R][T]
 Raw information regarding millisecond results.
long NStimes [R][T]
 Raw information regarding nanosecond results.
timespec before
 Time (in nanoseconds) after process completes.
timespec after
 Time (in nanoseconds) after process completes.
timeval beforeV
 Time before process starts.
timeval afterV
 Time after process completes.
char buf [1024]
 More than enough scratch room.


Detailed Description

Show timing example in both milliseconds and nanonseconds. Show the ability on Unix systems to time both using milliseconds and nanosecond timers.

Must be compiled with the -lrt libraries.

Author:
George Heineman
Date:
6/15/08

Define Documentation

#define R   5

Number of rows to compute.

#define T   30

For each row, the number of trials to execute.


Function Documentation

char* buildRow ( long  n,
long  times[R][T] 
)

Build a row for the output by computing average and stdev after discarding the lowest and highest results.

void buildTable ( long  times[R][T]  ) 

long diffNanoTimer ( struct timespec *  before,
struct timespec *  after 
)

Compute the difference between two time values in usecs.

int main ( int  argc,
char **  argv 
)

Compute the addition of numbers in range 1,000,000 to 5,000,000 for a fixed number of trials.

Using this information we create a histogram of sorts and output the reults.


Variable Documentation

struct timespec after

Time (in nanoseconds) after process completes.

struct timeval afterV

Time after process completes.

struct timespec before

Time (in nanoseconds) after process completes.

struct timeval beforeV

Time before process starts.

char buf[1024]

More than enough scratch room.

long MStimes[R][T]

Raw information regarding millisecond results.

long NStimes[R][T]

Raw information regarding nanosecond results.

Algorithm Development Kit 1.0