Closed helpermethod closed 10 years ago
Using date
for measuring execution time has several flaws:
%s
format specifier is not defined by POSIX%N
format specifier is not defined by POSIX and may not even be present on common platformsThus, some combination of the time
builtin and the TIMEFORMAT
environment variable is preferrable.
Measuring and accumulating now works but somehow a return code of 0 (i.e. success) is always returned (it seems that somehow the actual return code gets swallowed).
The return code of the command substitution got obscured by the local builtin (which has a return code by itself). Declaring the variable first (using the local keyword) and then assigning a value to it afterwards solved the problem.
As the time
command was executed in a subshell the error_message
global variable could not be set. Writing the output of time
to a file and not executing it in a subshell may solve the problem.
Example:
See this SO question to get an idea on how to implement this.