Add time measurement
This commit is contained in:
parent
07bb269175
commit
ab129bc6c8
@ -1,6 +1,8 @@
|
|||||||
#include <fmt/format.h>
|
#include <fmt/format.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <string>
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
#include <mergesort.h>
|
#include <mergesort.h>
|
||||||
|
|
||||||
@ -20,43 +22,45 @@ Does α depend on the size of the input? If it does, how should you modify
|
|||||||
your predictions and their graphical illustration?
|
your predictions and their graphical illustration?
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
auto parse_file(std::ifstream &stream, std::vector<T> &vec) -> void {
|
||||||
|
std::string buf;
|
||||||
|
T convbuf;
|
||||||
|
|
||||||
|
while (std::getline(stream, buf)) {
|
||||||
|
|
||||||
|
convbuf = static_cast<T>(std::stoul(buf));
|
||||||
|
|
||||||
|
vec.emplace_back(std::move(convbuf));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
try {
|
try {
|
||||||
std::ifstream file("dataset.dat", std::ios_base::in);
|
std::ifstream file("dataset.dat", std::ios_base::in);
|
||||||
|
if (!file.is_open()) {
|
||||||
|
fmt::print("Error opening file");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
fmt::print("Opened file {} sucessfully!\n", "dummy");
|
fmt::print("Opened file {} sucessfully!\n", "dummy");
|
||||||
|
std::vector<int32_t> dataset;
|
||||||
|
|
||||||
std::vector<int32_t> dataset{10, 3, 244, 23, 293, 2393, 302};
|
parse_file(file, dataset);
|
||||||
|
fmt::print("Read {} values from {}\n", dataset.size(), "dummy");
|
||||||
|
|
||||||
// std::vector<int32_t> dataset;
|
auto t1 = std::chrono::high_resolution_clock::now();
|
||||||
// int counter = 0;
|
|
||||||
//
|
|
||||||
// while(!file.eof()) {
|
|
||||||
// int32_t buf;
|
|
||||||
// file >> buf;
|
|
||||||
// dataset.emplace_back(buf);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// fmt::print("Read {} values from {}\n", dataset.size(), "dummy");
|
|
||||||
|
|
||||||
algo::mergesort(dataset.begin(), dataset.end(), [](int32_t a, int32_t b) {
|
algo::mergesort(dataset.begin(), dataset.end(), [](int32_t a, int32_t b) {
|
||||||
return (a>b);
|
return (a > b);
|
||||||
});
|
});
|
||||||
|
|
||||||
fmt::print("sorted");
|
auto t2 = std::chrono::high_resolution_clock::now();
|
||||||
|
|
||||||
// QFile outfile("dataset-sorted.dat");
|
|
||||||
// if(!outfile.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
auto delay_ms = std::chrono::duration_cast<std::chrono::milliseconds>(t2 - t1);
|
||||||
// fmt::print("Error! Could not create output file");
|
fmt::print("Sorted {} entries within {} ms.", dataset.size(), delay_ms.count());
|
||||||
// }
|
|
||||||
//
|
|
||||||
// for(auto &val : dataset) {
|
|
||||||
// outfile.write(fmt::format("{}\n", val).c_str());
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// file.close();
|
|
||||||
// outfile.flush();
|
|
||||||
// outfile.close();
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user