Program to implement time delay, pause and measure timings for a particular event in C++.

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include<iostream.h>

void sleep( clock_t  );

void main( void )
{
long    i = 600000L;
clock_t start, finish;
double  duration;
printf("%d\n",(int)CLOCKS_PER_SEC);

/* Delay for a specified time. */
printf( "Delay for three seconds\n" );
sleep( (clock_t)3 * CLOCKS_PER_SEC );
printf( "Done!\n" );


/* Measure the duration of an event. */
printf( "Time to do %ld empty loops is ", i );
start = clock();
while( i-- )
cout<<endl;
finish = clock();
duration = (float)(finish - start) / CLOCKS_PER_SEC;
printf( "%2.5f seconds\n", duration );
}

/* Pauses for a specified number of milliseconds. */
void sleep( clock_t waitme )
{
clock_t goal;
goal = waitme + clock();
while( goal > clock() )
;
}
Advertisements

14 thoughts on “Program to implement time delay, pause and measure timings for a particular event in C++.

  1. Does your website have a contact page? I’m having a tough time locating it but, I’d like
    to shoot you an e-mail. I’ve got some creative ideas for your blog you might be interested in hearing. Either way, great site and I look forward to seeing it expand over time.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s