21
21
* -------------------------------------------------------------------------- */
22
22
23
23
#include " OpenSim/Common/C3DFileAdapter.h"
24
- #include " OpenSim/Common/TRCFileAdapter.h"
25
24
#include " OpenSim/Common/STOFileAdapter.h"
26
- #include < OpenSim/Auxiliary/auxiliaryTestFunctions.h>
27
-
28
- #include < vector>
29
- #include < unordered_map>
30
- #include < cstdlib>
25
+ #include " OpenSim/Common/TRCFileAdapter.h"
31
26
#include < chrono>
32
- #include < thread>
33
27
#include < cmath>
28
+ #include < cstdlib>
29
+ #include < thread>
30
+ #include < unordered_map>
31
+ #include < vector>
32
+
33
+ #include < OpenSim/Auxiliary/auxiliaryTestFunctions.h>
34
+ #include < OpenSim/Common/Stopwatch.h>
34
35
35
36
template <typename ETY = SimTK::Real>
36
37
void compare_tables (const OpenSim::TimeSeriesTable_<ETY>& table1,
@@ -77,26 +78,25 @@ void test(const std::string filename) {
77
78
using namespace std ;
78
79
79
80
// The walking C3D files included in this test should not take more
80
- // than 40ms on most hardware. We make the max time 100ms to account
81
+ // than 40ms on most hardware. We make the max time 200ms to account
81
82
// for potentially slower CI machines.
82
- const double MaximumLoadTimeInMS = 100 ;
83
+ const long long MaximumLoadTimeInNs = SimTK::secToNs ( 0.200 ) ;
83
84
84
- std:: clock_t startTime = std::clock () ;
85
+ Stopwatch watch ;
85
86
C3DFileAdapter c3dFileAdapter{};
86
87
auto tables = c3dFileAdapter.read (filename);
87
-
88
- double loadTime = 1 .e3 *(std::clock () - startTime) / CLOCKS_PER_SEC;
88
+ long long loadTime = watch.getElapsedTimeInNs ();
89
89
90
90
cout << " \t C3DFileAdapter '" << filename << " ' loaded in "
91
- << loadTime << " ms " << endl;
91
+ << watch. formatNs ( loadTime) << endl;
92
92
93
93
/* Disabled performance test because Travis CI is consistently unable to
94
94
meet this timing requirement. Consider PR#2221 to address this issue
95
95
longer term.
96
96
#ifdef NDEBUG
97
- ASSERT(loadTime < MaximumLoadTimeInMS , __FILE__, __LINE__,
97
+ ASSERT(loadTime < MaximumLoadTimeInNs , __FILE__, __LINE__,
98
98
"Unable to load '" + filename + "' within " +
99
- to_string(MaximumLoadTimeInMS ) + "ms .");
99
+ to_string(MaximumLoadTimeInNs ) + "ns .");
100
100
#endif
101
101
*/
102
102
@@ -117,28 +117,28 @@ void test(const std::string filename) {
117
117
marker_table->updTableMetaData ().setValueForKey (" Units" ,
118
118
std::string{" mm" });
119
119
TRCFileAdapter trc_adapter{};
120
- std:: clock_t t0 = std::clock ();
120
+ watch. reset ();
121
121
trc_adapter.write (*marker_table, marker_file);
122
122
cout << " \t Wrote '" << marker_file << " ' in "
123
- << 1 . e3 *( std::clock () - t0) / CLOCKS_PER_SEC << " ms " << endl;
123
+ << watch. getElapsedTimeFormatted () << endl;
124
124
125
125
ASSERT (force_table->getNumRows () > 0 , __FILE__, __LINE__,
126
126
" Failed to read forces data from " + filename);
127
127
128
128
force_table->updTableMetaData ().setValueForKey (" Units" ,
129
129
std::string{" mm" });
130
130
STOFileAdapter sto_adapter{};
131
- t0 = std::clock ();
131
+ watch. reset ();
132
132
sto_adapter.write ((force_table->flatten ()), forces_file);
133
133
cout << " \t Wrote'" << forces_file << " ' in "
134
- << 1 . e3 *( std::clock () - t0) / CLOCKS_PER_SEC << " ms " << endl;
134
+ << watch. getElapsedTimeFormatted () << endl;
135
135
136
136
// Verify that marker data was written out and can be read in
137
- t0 = std::clock ();
137
+ watch. reset ();
138
138
TimeSeriesTable_<SimTK::Vec3> markers (marker_file);
139
139
TimeSeriesTable_<SimTK::Vec3> std_markers (" std_" + marker_file);
140
140
cout << " \t Read'" << marker_file << " ' and its standard in "
141
- << 1 . e3 *( std::clock () - t0) / CLOCKS_PER_SEC << " ms " << endl;
141
+ << watch. getElapsedTimeFormatted () << endl;
142
142
143
143
// Compare C3DFileAdapter read-in and written marker data
144
144
compare_tables<SimTK::Vec3>(markers, *marker_table);
@@ -161,22 +161,24 @@ void test(const std::string filename) {
161
161
162
162
cout << " \t Forces " << forces_file << " equivalent to standard." << endl;
163
163
164
- t0 = std::clock ();
165
- // Reread in C3D file with forces resolved to the COP
164
+ watch. reset ();
165
+ // Reread in C3D file with forces resolved to the COP
166
166
auto c3dFileAdapter2 = C3DFileAdapter{};
167
- c3dFileAdapter2.setLocationForForceExpression (C3DFileAdapter::ForceLocation::CenterOfPressure);
167
+ c3dFileAdapter2.setLocationForForceExpression (
168
+ C3DFileAdapter::ForceLocation::CenterOfPressure);
168
169
auto tables2 = c3dFileAdapter2.read (filename);
169
170
170
- loadTime = 1 . e3 *( std::clock () - t0) / CLOCKS_PER_SEC ;
171
+ loadTime = watch. getElapsedTimeInNs () ;
171
172
cout << " \t C3DFileAdapter '" << filename << " ' read with forces at COP in "
172
- << loadTime << " ms " << endl;
173
+ << watch. formatNs ( loadTime) << endl;
173
174
// on ci-biulds will define SKIP_TIMING as it is unpredictably slow on some machines
174
175
#if defined(NDEBUG) && !defined(SKIP_TIMING)
175
- ASSERT (loadTime < MaximumLoadTimeInMS , __FILE__, __LINE__,
176
+ ASSERT (loadTime < MaximumLoadTimeInNs , __FILE__, __LINE__,
176
177
" Unable to load '" + filename + " ' within " +
177
- to_string (MaximumLoadTimeInMS ) + " ms ." );
178
+ to_string (MaximumLoadTimeInNs ) + " ns ." );
178
179
#endif
179
- std::shared_ptr<TimeSeriesTableVec3> force_table_cop = c3dFileAdapter.getForcesTable (tables2);
180
+ std::shared_ptr<TimeSeriesTableVec3> force_table_cop =
181
+ c3dFileAdapter.getForcesTable (tables2);
180
182
downsample_table (*force_table_cop, 100 );
181
183
182
184
sto_adapter.write (force_table_cop->flatten (), " cop_" + forces_file);
@@ -189,29 +191,11 @@ void test(const std::string filename) {
189
191
SimTK::SqrtEps);
190
192
191
193
cout << " \t cop_" << forces_file << " is equivalent to its standard." << endl;
192
-
193
- cout << " \t testC3DFileAdapter '" << filename << " ' completed in "
194
- << 1 .e3 *(std::clock () - startTime) / CLOCKS_PER_SEC << " ms" << endl;
195
-
196
194
}
197
195
198
196
int main () {
199
- std::vector<std::string> filenames{};
200
- filenames.push_back (" walking2.c3d" );
201
- filenames.push_back (" walking5.c3d" );
202
-
203
- for (const auto & filename : filenames) {
204
- std::cout << " \n Test reading '" + filename + " '." << std::endl;
205
- try {
206
- test (filename);
207
- }
208
- catch (const std::exception & ex) {
209
- std::cout << " testC3DFileAdapter FAILED: " << ex.what () << std::endl;
210
- return 1 ;
211
- }
212
- }
213
-
214
- std::cout << " \n All testC3DFileAdapter cases passed." << std::endl;
215
-
216
- return 0 ;
197
+ SimTK_START_TEST (" testC3DFileAdapter" );
198
+ SimTK_SUBTEST1 (test, " walking2.c3d" );
199
+ SimTK_SUBTEST1 (test, " walking5.c3d" );
200
+ SimTK_END_TEST ();
217
201
}
0 commit comments