diff --git a/nshlib/README.txt b/nshlib/README.txt index b6f0a6f97..80ddf77e0 100644 --- a/nshlib/README.txt +++ b/nshlib/README.txt @@ -1012,10 +1012,14 @@ o time "" nsh> time "sleep 2" - 2.0001 sec + 2.0100 sec + nsh> - The addition 100 microseconds in this example is the additional overhead - of the time command execution itself which is included in the total. + The additional 10 millseconds in this example is due primarily to the + quantization error in the timing (this setup used a 10 millisecond + periodic system timer). Other sources of error could include the + additional overhead of the time command execution itself which is + included in the total. Notice that: @@ -1023,9 +1027,16 @@ o time "" sleep [3:100] 0.0000 sec + nsh> Since the sleep command is executed in background, the sleep command - completes almost immediately. + completes almost immediately. As opposed to the following where the + time command is run in background with the sleep command: + + nsh> time "sleep 2" & + time [3:100] + nsh> + 2.0100 sec o unset diff --git a/nshlib/nsh_timcmds.c b/nshlib/nsh_timcmds.c index 1ae56dbc5..4a362fb7e 100644 --- a/nshlib/nsh_timcmds.c +++ b/nshlib/nsh_timcmds.c @@ -336,7 +336,7 @@ int cmd_time(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) diff.tv_nsec = end.tv_nsec - start.tv_nsec; nsh_output(vtbl, "\n%lu.%04lu sec\n", (unsigned long)diff.tv_sec, - (unsigned long)diff.tv_nsec / 10000000); + (unsigned long)diff.tv_nsec / 100000); } }