diff --git a/OpenSim/Common/Test/testC3DFileAdapter.cpp b/OpenSim/Common/Test/testC3DFileAdapter.cpp index 07852b5640..8dc15d0374 100644 --- a/OpenSim/Common/Test/testC3DFileAdapter.cpp +++ b/OpenSim/Common/Test/testC3DFileAdapter.cpp @@ -31,6 +31,8 @@ #include #include +static double MaximumLoadTimeInS = SimTK::NaN; + template void compare_tables(const OpenSim::TimeSeriesTable_& table1, const OpenSim::TimeSeriesTable_& table2, @@ -74,25 +76,22 @@ void downsample_table(OpenSim::TimeSeriesTable_& table, void test(const std::string filename) { using namespace OpenSim; using namespace std; + using namespace std::chrono; - // The walking C3D files included in this test should not take more - // than 40ms on most hardware. We make the max time 100ms to account - // for potentially slower CI machines. - const double MaximumLoadTimeInMS = 100; - - std::clock_t startTime = std::clock(); + steady_clock::time_point startTime = steady_clock::now(); auto tables = C3DFileAdapter::read(filename, C3DFileAdapter::ForceLocation::OriginOfForcePlate); - double loadTime = 1.e3*(std::clock() - startTime) / CLOCKS_PER_SEC; + steady_clock::time_point t2 = steady_clock::now(); + double loadTime = duration_cast>(t2 - startTime).count(); cout << "\tC3DFileAdapter '" << filename << "' loaded in " - << loadTime << "ms" << endl; + << loadTime << "s" << endl; #ifdef NDEBUG - ASSERT(loadTime < MaximumLoadTimeInMS, __FILE__, __LINE__, + ASSERT(loadTime < MaximumLoadTimeInS, __FILE__, __LINE__, "Unable to load '" + filename + "' within " + - to_string(MaximumLoadTimeInMS) + "ms."); + to_string(MaximumLoadTimeInS) + "s."); #endif auto& marker_table = tables.at("markers"); @@ -112,10 +111,11 @@ void test(const std::string filename) { marker_table->updTableMetaData().setValueForKey("Units", std::string{"mm"}); TRCFileAdapter trc_adapter{}; - std::clock_t t0 = std::clock(); + steady_clock::time_point t0 = steady_clock::now(); trc_adapter.write(*marker_table, marker_file); + t2 = steady_clock::now(); cout << "\tWrote '" << marker_file << "' in " - << 1.e3*(std::clock() - t0) / CLOCKS_PER_SEC << "ms" << endl; + << duration_cast>(t2 - t0).count() << "s" << endl; ASSERT(force_table->getNumRows() > 0, __FILE__, __LINE__, "Failed to read forces data from " + filename); @@ -123,17 +123,19 @@ void test(const std::string filename) { force_table->updTableMetaData().setValueForKey("Units", std::string{"mm"}); STOFileAdapter sto_adapter{}; - t0 = std::clock(); + t0 = steady_clock::now(); sto_adapter.write((force_table->flatten()), forces_file); + t2 = steady_clock::now(); cout << "\tWrote'" << forces_file << "' in " - << 1.e3*(std::clock() - t0) / CLOCKS_PER_SEC << "ms" << endl; + << duration_cast>(t2 - t0).count() << "s" << endl; // Verify that marker data was written out and can be read in - t0 = std::clock(); + t0 = steady_clock::now(); auto markers = trc_adapter.read(marker_file); auto std_markers = trc_adapter.read("std_" + marker_file); + t2 = steady_clock::now(); cout << "\tRead'" << marker_file << "' and its standard in " - << 1.e3*(std::clock() - t0) / CLOCKS_PER_SEC << "ms" << endl; + << duration_cast>(t2 - t0).count() << "s" << endl; // Compare C3DFileAdapter read-in and written marker data compare_tables(markers, *marker_table); @@ -156,20 +158,19 @@ void test(const std::string filename) { cout << "\tForces " << forces_file << " equivalent to standard." << endl; - - t0 = std::clock(); + t0 = steady_clock::now(); // Reread in C3D file with forces resolved to the COP auto tables2 = C3DFileAdapter::read(filename, C3DFileAdapter::ForceLocation::CenterOfPressure); - - loadTime = 1.e3*(std::clock() - t0) / CLOCKS_PER_SEC; + t2 = steady_clock::now(); + loadTime = duration_cast>(t2 - t0).count(); cout << "\tC3DFileAdapter '" << filename << "' read with forces at COP in " - << loadTime << "ms" << endl; + << loadTime << "s" << endl; #ifdef NDEBUG - ASSERT(loadTime < MaximumLoadTimeInMS, __FILE__, __LINE__, + ASSERT(loadTime < MaximumLoadTimeInS, __FILE__, __LINE__, "Unable to load '" + filename + "' within " + - to_string(MaximumLoadTimeInMS) + "ms."); + to_string(MaximumLoadTimeInS) + "s."); #endif auto& force_table_cop = tables2.at("forces"); @@ -186,11 +187,32 @@ void test(const std::string filename) { cout << "\tcop_" << forces_file << " is equivalent to its standard."<< endl; + t2 = steady_clock::now(); cout << "\ttestC3DFileAdapter '" << filename << "' completed in " - << 1.e3*(std::clock() - startTime) / CLOCKS_PER_SEC << "ms" << endl; + << duration_cast>(t2-startTime).count() << "s" << endl; } int main() { + using namespace OpenSim; + using namespace std; + using namespace std::chrono; + + steady_clock::time_point startTime = steady_clock::now(); + Storage("test.sto"); + steady_clock::time_point t2 = steady_clock::now(); + + auto benchLoadTime = duration_cast>(t2 - startTime).count(); + + // The walking C3D files included in this test are benchmarked against the + // load time for a standard 'test.sto' Storage that is 1KB in size. The load + // time is platform specific (e.g. CI machines). The C3D files are ~1000x + // larger than the benchmark file. Therefore, we make the maximum allowable + // load time 1000x the load time of the benchmark file. + MaximumLoadTimeInS = 1000 * benchLoadTime; + + cout << "Platform-specific Maximum allowable load time is " + << MaximumLoadTimeInS << "s" << endl; + std::vector filenames{}; filenames.push_back("walking2.c3d"); filenames.push_back("walking5.c3d");