Test our timer function : Timer « Development « C / ANSI-C

C / ANSI-C
1. assert.h
2. Console
3. ctype.h
4. Data Structure Algorithm
5. Data Type
6. Development
7. File
8. Function
9. Language Basics
10. Macro Preprocessor
11. Math
12. math.h
13. Memory
14. Pointer
15. setjmp.h
16. signal.h
17. Small Application
18. stdio.h
19. stdlib.h
20. String
21. string.h
22. Structure
23. time.h
24. wctype.h
Microsoft Office Word 2007 Tutorial
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
C / ANSI-C » Development » TimerScreenshots 
Test our timer function


/*
Beginning C, Third Edition
 By Ivor Horton
 ISBN: 1-59059-253-0
 Published: Apr 2004
 Publisher: apress

*/

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

void main()
{
  long count = 100000000;          /* Number of loop iterations */
  long i = 0;                      /* Loop counter              */
  time_t calendar = 0;             /* Holds calendar time       */
  clock_t now = 0;                 /* Holds initial clock time  */
  int interval = 3;                /* Seconds interval for o/p  */
  int elapsed = 0;                 /* Elapsed clock time secs.  */

  calendar = time(NULL);           /* Get current calendar time */
  now = clock();                   /* Get current clock time    */
  printf("Initial clock time = %d Initial calendar time = %d\n",
                                                       now, calendar);
    
    for(i = 0L ; i<count ; i++)
    {
      elapsed = (clock()-now)/CLOCKS_PER_SEC;
      if(elapsed>=interval)
      {
        interval += 3;
        printf("\nElapsed = %ld seconds  iterations = %ld", elapsed, i);
      }
    }

  printf("\nCPU time for %ld interations is %.2lf seconds\n",
                                count, (double)(clock()-now)/CLOCKS_PER_SEC );
  printf("\Final clock time = %d Final calendar time = %d\n",
                                                       clock(), time(NULL));
  printf("\nElapsed calendar time to execute the program is %lf\n",
                                           difftime(time(NULL), calendar));
}



           
       
Related examples in the same category
1. Display a software timerDisplay a software timer
w__w_w_.___j_a___v___a_2s__._c_o_m___ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.