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:
parent
1b61df2ad1
commit
a702f7fffc
@ -10,6 +10,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <sys/time.h> /* gettimeofday(), struct timeval */
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
#define eq(x, y) ( ( (x) == (y) ) || ( (x) == '?' ) || ( (y) == '?' ) )
|
#define eq(x, y) ( ( (x) == (y) ) || ( (x) == '?' ) || ( (y) == '?' ) )
|
||||||
@ -35,7 +36,14 @@ int main(int argc, char * argv[])
|
|||||||
readFile(argv[1], file1);
|
readFile(argv[1], file1);
|
||||||
readFile(argv[2], file2);
|
readFile(argv[2], file2);
|
||||||
|
|
||||||
|
struct timeval before, after;
|
||||||
|
gettimeofday(&before, NULL); /* Start timing */
|
||||||
similarityMatrix(file1, file2);
|
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 */
|
/* Read a file into a vector of non-space characters */
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
#include <sys/time.h> /* gettimeofday(), struct timeval */
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
#define eq(x, y) ( ( (x) == (y) ) || ( (x) == '?' ) || ( (y) == '?' ) )
|
#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)];
|
matrix = new int[(files[0].size() + 1) * (files[1].size() + 1)];
|
||||||
pthread_barrier_init(&barrier, NULL, num_threads);
|
pthread_barrier_init(&barrier, NULL, num_threads);
|
||||||
|
|
||||||
|
struct timeval before, after;
|
||||||
|
gettimeofday(&before, NULL); /* Start timing */
|
||||||
|
|
||||||
/* Create num_threads worker threads */
|
/* Create num_threads worker threads */
|
||||||
for (int i = 0; i < num_threads; i++)
|
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 ("
|
cout << "Maximum value is " << max_val << " at position ("
|
||||||
<< max_i << ", " << max_j << ")" << endl;
|
<< 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 */
|
/* Clean up after ourselves */
|
||||||
pthread_barrier_destroy(&barrier);
|
pthread_barrier_destroy(&barrier);
|
||||||
delete[] matrix;
|
delete[] matrix;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user