Title: High Speed Timer Post by: smi256 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(); } Title: High Speed Timer Post by: smi256 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 :P * 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; } |