john pfeiffer
  • Home
  • Categories
  • Tags
  • Archives

execute time testing

/* 22 jun 07  John Pfeiffer testing how to test my prog efficiency */
#include <stdio.h>
#include <time.h>   /* time() is totally inefficient for small progs! */

int main()
{
    float start=0;
    float middle=0;
    float end=0;

    int i=0;
    int k=0;
    int ar[2];

    start = time(0);
    printf("start with time():  %d\n", time(0) - start);         
    printf("start with clock(): %d\n\n",clock() ); /* CLOCK must be an int!!! */

    for( i=0; i < 100; i++)
    {
        ar[0] = i;          
        ar[1] = i+1;        
        for(k=0; k<100; k++)
        {
            ar[0] = k;
            ar[1] = k+1;        
        }
    }

    middle = time(0);
    printf("first task with time():  %f\n", start - middle);  
    printf("first task clock(): %d\n\n",clock());

    for(i=0; i<100; i++)
    {
        ar[0] = i+1;
        ar[1] = i;        
        for(k=0; k<100; k++)
        {
            ar[0] = k+1;
            ar[1] = k;        
        }
    }

    end = time(0);
    printf("second leg with time(): %f\n", (end - middle) );    
    printf("end with time():  %f\n", time(0) - start);            
    printf("end with clock(): %d\n",clock());


    return 0;
}

  • « ascii char int printout
  • word count »

Published

Jun 22, 2007

Category

c

~119 words

Tags

  • c 95
  • execute 3
  • testing 6
  • time 13