فهرست منبع

timealgorithms.cxx now produces a csv file

Natalie Pueyo 8 سال پیش
والد
کامیت
215e54f427
3فایلهای تغییر یافته به همراه49 افزوده شده و 35 حذف شده
  1. 3 0
      timealgorithms.csv
  2. 46 35
      timealgorithms.cxx
  3. BIN
      timealgorithms.exe

+ 3 - 0
timealgorithms.csv

@@ -0,0 +1,3 @@
+Sample,InsertionSortTime,InsertionSortCompares,InsertionSortMemaccess,MergeSortTime,MergeSortCompares,MergeSortMemaccess,QuickSortTime,QuickSortCompares,QuickSortMemaccess,
+Sample1,0,3,3,0,4,24,0,5,8,
+Sample2,0,7,27,0,4,24,0,5,8,

+ 46 - 35
timealgorithms.cxx

@@ -21,6 +21,11 @@ int main(int argc, char* argv[]) {
     file >> jsonObject;
   }
 
+  // initiate CSV file quickto which data will be written
+  std::ofstream theFile;
+  theFile.open("timealgorithms.csv");
+  theFile << "Sample,InsertionSortTime,InsertionSortCompares,InsertionSortMemaccess,MergeSortTime,MergeSortCompares,MergeSortMemaccess,QuickSortTime,QuickSortCompares,QuickSortMemaccess,\n";
+
   // initialize array for JSON data
   //int n = jsonObject["metadata"]["arraySize"];
   std::vector<int>* sampleArray = new std::vector<int>();
@@ -42,51 +47,57 @@ int main(int argc, char* argv[]) {
 
   for (auto itr = jsonObject.begin(); itr != jsonObject.end(); ++itr) {
     sampleName = itr.key();
-    //int arrayElement = 0;
 
     if (sampleName != "metadata") {
       for (auto arrayItr = jsonObject[sampleName].begin(); arrayItr != jsonObject[sampleName].end(); ++arrayItr) {
-        //sampleArray[arrayElement] = *arrayItr;
-        //sampleArray.push_back(*arrayItr);
         sampleArray -> push_back(*arrayItr);
-        //arrayElement++;
       }
-    }
-  }
+      // Add the sample name to the CSV file line
+      theFile << itr.key() << ",";
 
-  for (auto const &element: *sampleArray){
-      std::cout << element << ' ' << std::endl;
-  }
+      // insertion sort evaluation
+      insStartTime = time(0);
+      insReturnArray = InsertionSort(sampleArray);
+      insTime = time(0) - insStartTime;
+      std::cout << "insertion sort comparison counter: " << *insReturnArray << std::endl;
+      std::cout << "insertion sort memory access counter: " << *(insReturnArray + 1) << std::endl;
+      std::cout << "wallclock time for insertion sort: " << insTime << std::endl;
+      // Add the insertion sort data to the CSV file line
+      theFile << insTime << "," << *insReturnArray << "," << *(insReturnArray + 1) << "," ;
 
-  // insertion sort evaluation
-  insStartTime = time(0);
-  insReturnArray = InsertionSort(sampleArray);
-  insTime = time(0) - insStartTime;
-  std::cout << "insertion sort comparison counter: " << *insReturnArray << std::endl;
-  std::cout << "insertion sort memory access counter: " << *(insReturnArray + 1) << std::endl;
-  std::cout << "wallclock time for insertion sort: " << insTime << std::endl;
+      // merge sort evaluation
+      merStartTime = time(0);
+      mergeReturnArray = MergeSort(sampleArray);
+      merTime = time(0) - merStartTime;
+      std::cout << "merge sort comparison counter: " << *mergeReturnArray << std::endl;
+      std::cout << "merge sort memory access counter: " << *(mergeReturnArray + 1) << std::endl;
+      std::cout << "wallclock time for merge sort: " << merTime << std::endl;
+      // Add the merge sort data to the CSV file line
+      theFile << merTime << "," << *mergeReturnArray << "," << *(mergeReturnArray + 1) << "," ;
 
-  // merge sort evaluation
-  merStartTime = time(0);
-  mergeReturnArray = MergeSort(sampleArray);
-  merTime = time(0) - merStartTime;
-  std::cout << "merge sort comparison counter: " << *mergeReturnArray << std::endl;
-  std::cout << "merge sort memory access counter: " << *(mergeReturnArray + 1) << std::endl;
-  std::cout << "wallclock time for merge sort: " << merTime << std::endl;
 
-  quickStartTime = time(0);
-  quickReturnArray = QuickSort(sampleArray);
-  quickTime = time(0) - quickStartTime;
-  std::cout << "quick sort comparison counter: " << *quickReturnArray << std::endl;
-  std::cout << "quick sort memory access counter: " << *(quickReturnArray + 1) << std::endl;
-  std::cout << "wallclock time for quick sort: " << quickTime << std::endl;
+      quickStartTime = time(0);
+      quickReturnArray = QuickSort(sampleArray);
+      quickTime = time(0) - quickStartTime;
+      std::cout << "quick sort comparison counter: " << *quickReturnArray << std::endl;
+      std::cout << "quick sort memory access counter: " << *(quickReturnArray + 1) << std::endl;
+      std::cout << "wallclock time for quick sort: " << quickTime << std::endl;
+      std::cout << std::endl;
+      // Add the quick sort data to the CSV file line
+      theFile << quickTime << "," << *quickReturnArray << "," << *(quickReturnArray + 1) << "," ;
+      theFile << "\n";
 
-  // initiate CSV file quickto which data will be written
-  //std::ofstream theFile;
-  //theFile.open("timingalgorithms.csv");
-  //theFile << "Sample,InsertionSortTime,InsertionSortCompares,InsertionSortMemaccess,MergeSortTime,MergeSortCompares,MergeSortMemaccess,QuickSortTime,QuickSortCompares,QuickSortMemaccess,\n";
+      // clear the array for the next sample
+      sampleArray -> clear();
+    }
+  }
+
+  // check to see if I'm getting all the sample elements in one array
+  /*for (auto const &element: *sampleArray){
+      std::cout << element << ' ' << std::endl;
+  }*/
 
-  //theFile.close();
-  file.close(); // close JSON file
+  theFile.close();   // close CSV file
+  file.close();      // close JSON file
   return 0;
 }

BIN
timealgorithms.exe