1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
#include <cstdlib>
#include <iostream>
#include <time.h>
#include <process.h>
#include <windows.h>
int x,y,z,a,b,c,math1[501],math2[501],times[10];
float avgtime=0;
HANDLE hands[3];
using namespace std;
void functionone(void *)
{
for(x=0;x<1000000;x++)
for(y=0;y<500;y++)
math1[y]=x/25;
SetEvent(hands[0]);
return;
}
void functiontwo(void *)
{
for(a=0;a<1000000;a++)
for(b=0;b<500;b++)
math2[b]=a/25;
SetEvent(hands[1]);
return;
}
int main(int argc, char *argv[])
{
time_t time1,time2;
hands[0]=CreateEvent(NULL,false,false,NULL);
hands[1]=CreateEvent(NULL,false,false,NULL);
for(z=0;z<10;z++)
{
time1=time(NULL);
_beginthread(functionone,0,0);
_beginthread(functiontwo,0,0);
WaitForMultipleObjects(2,hands,true,INFINITE); //Pause for Threads
time2=time(NULL);
times[z]=time2-time1;
}
for(z=0;z<10;z++) avgtime+=times[z];
cout<<"Functions Complete in "<<avgtime/10<<" seconds.";
system("PAUSE");
return EXIT_SUCCESS;
}
|