I am looking for the best method to measure the running time of a code in each supported language. Yes, the answer is there in the 27 language documentations, but maybe the community could help me out much faster and better, please?
Something like this pseudocode:
start timer // .. do stuff get elapsed time in millisecs print it to standard error stream formatted
For a start, here it is in PHP:
$startTime = microtime(TRUE); // do stuff $thinkTime = microtime(TRUE) - $startTime; error_log('Think time = ' . number_format($thinkTime, 4, '.', '') . ' sec');
Note: microtime() can and shall be replaced with hrtime() as soon as CG moves up to PHP 7.4.
How to best do this in C#, C++, Java, Python, Haskell, etc? Please also add ‘import’ clauses if needed.