diff --git a/cs677/pa2/sequential.cc b/cs677/pa2/sequential.cc index 364c405..2aacac4 100644 --- a/cs677/pa2/sequential.cc +++ b/cs677/pa2/sequential.cc @@ -10,6 +10,7 @@ #include #include #include +#include /* 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 */ diff --git a/cs677/pa2/threaded.cc b/cs677/pa2/threaded.cc index 04f9401..04aaee6 100644 --- a/cs677/pa2/threaded.cc +++ b/cs677/pa2/threaded.cc @@ -11,6 +11,7 @@ #include #include #include +#include /* 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;