/*************************************************************************** * Copyright (C) 2010 by Michael Fischer * * fischer-michael@cs.yale.edu * * * * For use in Yale course CPSC 467b, Spring 2010 * ***************************************************************************/ #include #include "stopwatch.h" void startTime( stopwatch* sw ) { gettimeofday( &sw->start, NULL ); } void stopTime( stopwatch* sw ) { gettimeofday( &sw->stop, NULL ); } void printElapsedTime( stopwatch* sw ) { int seconds = sw->stop.tv_sec - sw->start.tv_sec; int useconds = sw->stop.tv_usec - sw->start.tv_usec; if ( useconds < 0 ) { useconds += 1000000; seconds--; } printf( "Elapsed time %d.%06d\n", seconds, useconds); }