diff options
author | Steve Bennett <steveb@workware.net.au> | 2020-06-07 13:22:14 +1000 |
---|---|---|
committer | Steve Bennett <steveb@workware.net.au> | 2020-06-11 08:16:14 +1000 |
commit | 165c05e397d1a26f04808834257752a133ff4f70 (patch) | |
tree | 96fd43b8789230dbeb3d995b6ec74d71fd5dfb0d | |
parent | 64ec09d155efbb03b878f0891ac3a8694e0b01ea (diff) | |
download | jimtcl-165c05e397d1a26f04808834257752a133ff4f70.zip jimtcl-165c05e397d1a26f04808834257752a133ff4f70.tar.gz jimtcl-165c05e397d1a26f04808834257752a133ff4f70.tar.bz2 |
time: show results less than 1us per iteration
In this case, show the result as a decimal value
Signed-off-by: Steve Bennett <steveb@workware.net.au>
-rw-r--r-- | jim.c | 11 |
1 files changed, 7 insertions, 4 deletions
@@ -13828,8 +13828,6 @@ static int Jim_TimeCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *arg { long i, count = 1; jim_wide start, elapsed; - char buf[60]; - const char *fmt = "%" JIM_WIDE_MODIFIER " microseconds per iteration"; if (argc < 2) { Jim_WrongNumArgs(interp, 1, argv, "script ?count?"); @@ -13852,8 +13850,13 @@ static int Jim_TimeCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *arg } } elapsed = JimClock() - start; - sprintf(buf, fmt, count == 0 ? 0 : elapsed / count); - Jim_SetResultString(interp, buf, -1); + if (elapsed < count * 10) { + Jim_SetResult(interp, Jim_NewDoubleObj(interp, elapsed * 1.0 / count)); + } + else { + Jim_SetResultInt(interp, count == 0 ? 0 : elapsed / count); + } + Jim_AppendString(interp, Jim_GetResult(interp)," microseconds per iteration", -1); return JIM_OK; } |