programs/timefn: Don't use clock() on Unix when C < 11 to improve multi-thread benchmark#3165
programs/timefn: Don't use clock() on Unix when C < 11 to improve multi-thread benchmark#3165Cyan4973 merged 1 commit intofacebook:clock_gettimefrom jbeich:timespec
Conversation
|
I just came to the same conclusion. The "bad performance" is a measurement error in zstdcli, not an actual performance issue. The libzstd produced with c11 and c99 are identical. |
|
I think this patch goes in the right direction. I'm actually surprised we don't use minor : I understand that edit : I just checked, and indeed |
|
Note : It does fix It's not necessarily a problem for this PR, which provides It just shows there is a bit more to do to address #3163 specifically. |
- cmake/meson pass -std=gnu99 which hits clock() fallback - clock() fallback skews multi-threading benchmarks - TIME_UTC (C11) is similar to CLOCK_REALTIME (POSIX) - GNU may hide CLOCK_REALTIME in -std=c99 (__STRICT_ANSI__) - Switch to CLOCK_MONOTONIC like before 36d2dfd
Addressed via file-local |
| * You may select, at your option, one of the above-listed licenses. | ||
| */ | ||
|
|
||
| #define _POSIX_C_SOURCE 200809L /* clock_gettime */ |
There was a problem hiding this comment.
I believe this should rather be defined in timefn.h, just before the #include <time.h>,
otherwise, UTIL_time_t declaration in timefn.h will be out of sync with timefn.c.
edit : although, note the following compilation issue :
../programs/timefn.h:22:0: error: "_POSIX_C_SOURCE" redefined [-Werror]
|
With #3163 out of the way, let's now focus on this PR. |
which restore clock_gettime() as a way to get a usable timer for posix systems. Original PR by @jbeich
which restore clock_gettime() as a way to get a usable timer for posix systems. Original PR by @jbeich
Fixes #3163
See also freebsd/freebsd-src@6882d53b7fb8
See also aosp-mirror/platform_bionic@78e9ebc3b968
C90 aka
clock()fallback being suboptimal seems to be known issue:zstd/programs/timefn.c
Lines 138 to 143 in b7b7edb