November 22, 2024, 05:56:10 AM

News : LinuxSolved.com Linux Help Community Forum..


Author Topic: Time based output  (Read 5635 times)

Offline vivasaayi

  • New Member
  • Posts: 1
Time based output
« on: December 28, 2008, 04:53:27 PM »
This program provides the cpu time used by the program at the end of the program execution.

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

int main(int argc, char *argv[]) {
clock_t ticks;
int i=0;
while(i<50000)
{
printf("Work work %d\n", i);
i++;
ticks = clock();
}
printf("Used %0.2f seconds of CPU time. \n", (double)ticks/CLOCKS_PER_SEC);
}

I need the output(cpu time used) for every 100 milliseconds of the total execution period instead of getting the output for the overall execution period.How to do it?.

for example

suppose the program takes 1000 milliseconds to finish overall.


I need the output like

the cpu time used by the program for first 100 ms = 15 ms

the cpu time used by the program for second 100ms = 20 ms

the cpu time used by the program for the third 100 ms = 10 ms

.
.
.
the cpu time used by the program for the tenth 100ms = 2 ms