mirror of
https://github.com/jedisct1/libsodium.git
synced 2024-12-23 20:15:19 -07:00
Use CLOCK_MONOTONIC for benchmarking, if possible
This commit is contained in:
parent
ee009287af
commit
05b8da1a49
@ -70,6 +70,7 @@ pub fn build(b: *std.build.Builder) !void {
|
|||||||
|
|
||||||
lib.defineCMacro("HAVE_CATCHABLE_ABRT", "1");
|
lib.defineCMacro("HAVE_CATCHABLE_ABRT", "1");
|
||||||
lib.defineCMacro("HAVE_CATCHABLE_SEGV", "1");
|
lib.defineCMacro("HAVE_CATCHABLE_SEGV", "1");
|
||||||
|
lib.defineCMacro("HAVE_CLOCK_GETTIME", "1");
|
||||||
lib.defineCMacro("HAVE_GETPID", "1");
|
lib.defineCMacro("HAVE_GETPID", "1");
|
||||||
lib.defineCMacro("HAVE_INLINE_ASM", "1");
|
lib.defineCMacro("HAVE_INLINE_ASM", "1");
|
||||||
lib.defineCMacro("HAVE_MADVISE", "1");
|
lib.defineCMacro("HAVE_MADVISE", "1");
|
||||||
@ -100,6 +101,7 @@ pub fn build(b: *std.build.Builder) !void {
|
|||||||
lib.defineCMacro("HAVE_ARC4RANDOM_BUF", "1");
|
lib.defineCMacro("HAVE_ARC4RANDOM_BUF", "1");
|
||||||
lib.defineCMacro("HAVE_CATCHABLE_ABRT", "1");
|
lib.defineCMacro("HAVE_CATCHABLE_ABRT", "1");
|
||||||
lib.defineCMacro("HAVE_CATCHABLE_SEGV", "1");
|
lib.defineCMacro("HAVE_CATCHABLE_SEGV", "1");
|
||||||
|
lib.defineCMacro("HAVE_CLOCK_GETTIME", "1");
|
||||||
lib.defineCMacro("HAVE_GETENTROPY", "1");
|
lib.defineCMacro("HAVE_GETENTROPY", "1");
|
||||||
lib.defineCMacro("HAVE_GETPID", "1");
|
lib.defineCMacro("HAVE_GETPID", "1");
|
||||||
lib.defineCMacro("HAVE_MADVISE", "1");
|
lib.defineCMacro("HAVE_MADVISE", "1");
|
||||||
@ -121,6 +123,7 @@ pub fn build(b: *std.build.Builder) !void {
|
|||||||
.wasi => {
|
.wasi => {
|
||||||
lib.defineCMacro("HAVE_ARC4RANDOM", "1");
|
lib.defineCMacro("HAVE_ARC4RANDOM", "1");
|
||||||
lib.defineCMacro("HAVE_ARC4RANDOM_BUF", "1");
|
lib.defineCMacro("HAVE_ARC4RANDOM_BUF", "1");
|
||||||
|
lib.defineCMacro("HAVE_CLOCK_GETTIME", "1");
|
||||||
lib.defineCMacro("HAVE_GETENTROPY", "1");
|
lib.defineCMacro("HAVE_GETENTROPY", "1");
|
||||||
lib.defineCMacro("HAVE_NANOSLEEP", "1");
|
lib.defineCMacro("HAVE_NANOSLEEP", "1");
|
||||||
lib.defineCMacro("HAVE_POSIX_MEMALIGN", "1");
|
lib.defineCMacro("HAVE_POSIX_MEMALIGN", "1");
|
||||||
|
@ -905,7 +905,7 @@ AS_IF([test "x$WASI" = "x"],[
|
|||||||
AC_CHECK_FUNCS([getauxva elf_aux_info])
|
AC_CHECK_FUNCS([getauxva elf_aux_info])
|
||||||
])
|
])
|
||||||
|
|
||||||
AC_CHECK_FUNCS([posix_memalign nanosleep])
|
AC_CHECK_FUNCS([posix_memalign nanosleep clock_gettime])
|
||||||
|
|
||||||
AS_IF([test "x$WASI" = "x"],[
|
AS_IF([test "x$WASI" = "x"],[
|
||||||
AC_CHECK_FUNCS([memset_s explicit_bzero memset_explicit explicit_memset])
|
AC_CHECK_FUNCS([memset_s explicit_bzero memset_explicit explicit_memset])
|
||||||
|
@ -118,16 +118,23 @@ static int mempool_free_all(void)
|
|||||||
|
|
||||||
static unsigned long long now(void)
|
static unsigned long long now(void)
|
||||||
{
|
{
|
||||||
struct timeval tp;
|
#if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC)
|
||||||
unsigned long long now;
|
struct timespec tp;
|
||||||
|
|
||||||
|
if (clock_gettime(CLOCK_MONOTONIC, &tp) != 0) {
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
return (unsigned long long) tp.tv_sec * 1000000ULL +
|
||||||
|
(unsigned long long) tp.tv_nsec / 1000ULL;
|
||||||
|
#else
|
||||||
|
struct timeval tp;
|
||||||
|
|
||||||
if (gettimeofday(&tp, NULL) != 0) {
|
if (gettimeofday(&tp, NULL) != 0) {
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
now = ((unsigned long long) tp.tv_sec * 1000000ULL) +
|
return (unsigned long long) tp.tv_sec * 1000000ULL +
|
||||||
(unsigned long long) tp.tv_usec;
|
(unsigned long long) tp.tv_usec;
|
||||||
|
#endif
|
||||||
return now;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
|
Loading…
Reference in New Issue
Block a user