| 211 | } |
| 212 | |
| 213 | void DebugTestApp::testPerformance() |
| 214 | { |
| 215 | |
| 216 | log::manager()->restoreToDefault(); |
| 217 | CI_LOG_I( "\n--- TESTING PERFORMANCE START----"); |
| 218 | CI_LOG_I( "... this may take a while, don't fret." ); |
| 219 | |
| 220 | log::manager()->clearLoggers(); |
| 221 | |
| 222 | typedef struct { |
| 223 | double duration; |
| 224 | int hits; |
| 225 | } LogMeasure; |
| 226 | |
| 227 | auto looper = [](std::string log, LogMeasure &stats ) { |
| 228 | |
| 229 | shared_ptr<log::LoggerFile> logger = nullptr; |
| 230 | if( !log.empty() ) { |
| 231 | logger = log::makeLogger<log::LoggerFile>( log, false ); |
| 232 | } |
| 233 | int logHits = 0; |
| 234 | ci::Timer timer; |
| 235 | timer.start(); |
| 236 | for( int i=0; i<1000; ++i ) { |
| 237 | for( int j=0; j<1000; ++j ) { |
| 238 | CI_LOG_D( ++logHits ); |
| 239 | } |
| 240 | } |
| 241 | timer.stop(); |
| 242 | |
| 243 | if( logger ) { |
| 244 | // clean up our mess |
| 245 | auto path = logger->getFilePath(); |
| 246 | log::manager()->removeLogger( logger ); |
| 247 | logger.reset(); |
| 248 | fs::remove( path ); |
| 249 | } |
| 250 | |
| 251 | stats.hits = logHits; |
| 252 | stats.duration = timer.getSeconds(); |
| 253 | }; |
| 254 | |
| 255 | LogMeasure run1, run2, run3, run4, run5, run6; |
| 256 | |
| 257 | // test single log single thread |
| 258 | looper( "/tmp/performance.log", run1 ); |
| 259 | |
| 260 | // test two threads single log |
| 261 | std::thread t1( [ looper, &run2 ] () { looper( "/tmp/performance.log", run2 ); } ); |
| 262 | std::thread t2( [ looper, &run3 ] () { looper( "", run3 ); } ); |
| 263 | |
| 264 | t1.join(); |
| 265 | t2.join(); |
| 266 | |
| 267 | // test three threads single log |
| 268 | std::thread t3( [ looper, &run4 ] () { looper( "/tmp/performance.log", run4 ); } ); |
| 269 | std::thread t4( [ looper, &run5 ] () { looper( "", run5 ); } ); |
| 270 | std::thread t5( [ looper, &run6 ] () { looper( "", run6 ); } ); |
nothing calls this directly
no test coverage detected