Skip to content

Commit

Permalink
keep track of timing
Browse files Browse the repository at this point in the history
  • Loading branch information
philippwindischhofer committed Jan 29, 2024
1 parent 3ade53b commit 7f57e8b
Showing 1 changed file with 32 additions and 8 deletions.
40 changes: 32 additions & 8 deletions tests/io/testSerialization.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,24 @@

#include <fstream>
#include <iostream>
#include <chrono>
#include <random>

int main(int argc, char* argv[]) {
int test_serialization_vector(std::string ser_path, std::size_t length) {

using vector_t = std::vector<scalar_t>;

std::random_device rd;
std::mt19937 gen(rd());
std::uniform_real_distribution<> dis(1.0, 2.0);

vector_t vec = {-1, -2, 3, 4};
// Generate random vector
vector_t vec;
for(std::size_t ind = 0; ind < length; ind++) {
vec.push_back(dis(gen));
}

std::string ser_path = "ser_test.bin";
std::chrono::high_resolution_clock::time_point t_start = std::chrono::high_resolution_clock::now();

std::fstream ofs;
ofs.open(ser_path, std::ios::out | std::ios::binary);
Expand All @@ -20,12 +30,26 @@ int main(int argc, char* argv[]) {

std::fstream ifs;
ifs.open(ser_path, std::ios::in | std::ios::binary);
stor::Serializer iser(ifs);

stor::Serializer iser(ifs);
vector_t res = iser.deserialize<vector_t>();
ifs.close();
ifs.close();

std::chrono::high_resolution_clock::time_point t_end = std::chrono::high_resolution_clock::now();

for(auto cur: res) {
std::cout << cur << std::endl;
std::chrono::duration<double> time_span = duration_cast<std::chrono::duration<double>>(t_end - t_start);
std::cout << "It took me " << time_span.count() << " seconds." << std::endl;

for(std::size_t ind = 0; ind < length; ind++) {
if(vec[ind] != res[ind]) {
throw std::runtime_error("Error: mistake");
}
}

return 0;
}

int main(int argc, char* argv[]) {

std::string ser_path = "ser_test.bin";
test_serialization_vector(ser_path, 100000);
}

0 comments on commit 7f57e8b

Please sign in to comment.