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
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 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__2__s_.__c__o_m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.