BPsite Forums
November 22, 2024, 11:54:11 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: BPSITE FOREVER!
 
   Home   Help Search Members Login Register  
Pages: [1]
  Print  
Author Topic: High Speed Timer  (Read 3838 times)
smi256
Hero Member
*****
Offline Offline

Posts: 2287



View Profile
« on: September 15, 2005, 07:45:54 PM »

As I’m sure most of you have already gotten the e-mail.
Quote

#include <stdio.h>
#include <windows.h>


main ()

/************   Your Variables   *************/
   char meh;
/*******************************************/


/*******************************************/
/*****   Variables needed to use Timer   *****/
/*******************************************/
/**/
   double  elapsedTimeSec = 0;
/**/   LARGE_INTEGER liStart, liFinish;
/**/   LARGE_INTEGER liFreq;
/**/   QueryPerformanceFrequency(&liFreq);
/*******************************************/

   
//////////////////////////////////////////

   QueryPerformanceCounter(&liStart);    //Start Timer
//////////////////////////////////////////


/*~~~~~~!!!   Your Code Here   !!!~~~~~~~~~*/
   

/////////////////////////////////////////

   QueryPerformanceCounter(&liFinish);   //Stop Timer
/////////////////////////////////////////

           
   elapsedTimeSec = (double)(liFinish.LowPart - liStart.LowPart)/(double)liFreq.LowPart;
   printf("n%0.6f secondsn",elapsedTimeSec);   //Store and Prints the time
   
   
   meh=getch();
}
« Last Edit: September 15, 2005, 07:48:52 PM by smi256 » Logged

*was here
smi256
Hero Member
*****
Offline Offline

Posts: 2287



View Profile
« Reply #1 on: September 20, 2005, 05:16:05 AM »

Here's how you use it... <_<
I think it'd be nice if people posted more though... cuz... I have no idea what people are thinking
/me needs to work on his physic powers :sheep:
Quote
/*******************************************
 * Name:              I almost post it, probably doesn't even matter any more Tongue
 * Course:            CIS 40
 * Assingment:        Pseudo Random # Gen
 * Compiler:          Div-C++
*******************************************/


#include <stdio.h>
#include <windows.h>
#define MINRAND 1
#define MAXRAND 1000


int random(int min, int max);
main()
{ /*********************************************/
   /******   Variables needed to use Timer   ******/
   /*********************************************/
   /**/
   double  elapsedTimeSec = 0;           /**/
   /**/
   LARGE_INTEGER liStart, liFinish;      /**/
   /**/
   LARGE_INTEGER liFreq;                 /**/
   /**/
   QueryPerformanceFrequency(&liFreq);  /**/
   /*********************************************/

   char meh;
   int i,j,k;
   FILE *f;
   f=fopen("rand.txt","w");
   printf("How many random numbers? ");
   scanf("%d",&j);
   fprintf(f,"a[%d]={",j);
//////////////////////////////////////////
   QueryPerformanceCounter(&liStart);     //Start Timer
//////////////////////////////////////////

   for(i=0;i<j;i++)
   {  k=random(MINRAND,MAXRAND);
      fprintf(f,"%d",k);
      if((i+1)<j)
         fprintf(f,",",k);
      printf("%5d\t",k);
      if((i+1)%100==0)
         printf("\nProgress: %d random numbers generated so far.\n\n",(i+1));
   }
///////////////////////////////////////////
   QueryPerformanceCounter(&liFinish);     //Stop Timer
///////////////////////////////////////////

   fprintf(f,"};");
   fclose(f);
   putch(7);
   elapsedTimeSec=(double)(liFinish.LowPart - liStart.LowPart)/(double)liFreq.LowPart;  //Save the time
   printf("\n\nIt took %0.6f seconds to generate %d random numbers\n",elapsedTimeSec,i);//Print the time
   printf("The numbers were stored in 'rand.txt'\nPress a key to close this window.");
   meh=getch();
}

int random(int min, int max)
{  static int seed;
   seed==0 ? srand(seed=time(NULL)): seed;
   return rand()%(max+1-min)+min;
}
« Last Edit: September 20, 2005, 05:17:38 AM by smi256 » Logged

*was here
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!