added timing info using gettimeofday() to determine elapsed time

git-svn-id: svn://anubis/gvsu@182 45c1a28c-8058-47b2-ae61-ca45b979098e
This commit is contained in:
josh 2008-09-27 21:42:20 +00:00
parent 1b61df2ad1
commit a702f7fffc
2 changed files with 18 additions and 0 deletions

View File

@ -10,6 +10,7 @@
#include <iostream>
#include <fstream>
#include <vector>
#include <sys/time.h> /* gettimeofday(), struct timeval */
using namespace std;
#define eq(x, y) ( ( (x) == (y) ) || ( (x) == '?' ) || ( (y) == '?' ) )
@ -35,7 +36,14 @@ int main(int argc, char * argv[])
readFile(argv[1], file1);
readFile(argv[2], file2);
struct timeval before, after;
gettimeofday(&before, NULL); /* Start timing */
similarityMatrix(file1, file2);
gettimeofday(&after, NULL); /* Stop timing */
double time_before = before.tv_sec + before.tv_usec / 1000000.0;
double time_after = after.tv_sec + after.tv_usec / 1000000.0;
double diff = time_after - time_before;
cout << "Elapsed time: " << diff << " seconds." << endl;
}
/* Read a file into a vector of non-space characters */

View File

@ -11,6 +11,7 @@
#include <fstream>
#include <vector>
#include <pthread.h>
#include <sys/time.h> /* gettimeofday(), struct timeval */
using namespace std;
#define eq(x, y) ( ( (x) == (y) ) || ( (x) == '?' ) || ( (y) == '?' ) )
@ -102,6 +103,9 @@ int main(int argc, char * argv[])
matrix = new int[(files[0].size() + 1) * (files[1].size() + 1)];
pthread_barrier_init(&barrier, NULL, num_threads);
struct timeval before, after;
gettimeofday(&before, NULL); /* Start timing */
/* Create num_threads worker threads */
for (int i = 0; i < num_threads; i++)
{
@ -142,6 +146,12 @@ int main(int argc, char * argv[])
cout << "Maximum value is " << max_val << " at position ("
<< max_i << ", " << max_j << ")" << endl;
gettimeofday(&after, NULL); /* Stop timing */
double time_before = before.tv_sec + before.tv_usec / 1000000.0;
double time_after = after.tv_sec + after.tv_usec / 1000000.0;
double diff = time_after - time_before;
cout << "Elapsed time: " << diff << " seconds." << endl;
/* Clean up after ourselves */
pthread_barrier_destroy(&barrier);
delete[] matrix;