diff --git a/src/native/containers/dn-simdhash-ght-compatible.c b/src/native/containers/dn-simdhash-ght-compatible.c index 6a17aed9177ca..330f2a14f7385 100644 --- a/src/native/containers/dn-simdhash-ght-compatible.c +++ b/src/native/containers/dn-simdhash-ght-compatible.c @@ -1,7 +1,9 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#ifndef NO_CONFIG_H #include +#endif #include "dn-simdhash.h" #include "dn-simdhash-utils.h" diff --git a/src/native/containers/dn-simdhash-ptr-ptr.c b/src/native/containers/dn-simdhash-ptr-ptr.c index 6e7b9b6893c86..25e7530d39dc4 100644 --- a/src/native/containers/dn-simdhash-ptr-ptr.c +++ b/src/native/containers/dn-simdhash-ptr-ptr.c @@ -1,7 +1,9 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#ifndef NO_CONFIG_H #include +#endif #include "dn-simdhash.h" #include "dn-simdhash-utils.h" diff --git a/src/native/containers/dn-simdhash.h b/src/native/containers/dn-simdhash.h index c8b8b890d467d..2a26083ec7df1 100644 --- a/src/native/containers/dn-simdhash.h +++ b/src/native/containers/dn-simdhash.h @@ -4,6 +4,7 @@ #ifndef __DN_SIMDHASH_H__ #define __DN_SIMDHASH_H__ +#include #include "dn-utils.h" #include "dn-allocator.h" diff --git a/src/native/containers/simdhash-benchmark/all-measurements.c b/src/native/containers/simdhash-benchmark/all-measurements.c index 0aa95f70f5bb7..2d04bbd427012 100644 --- a/src/native/containers/simdhash-benchmark/all-measurements.c +++ b/src/native/containers/simdhash-benchmark/all-measurements.c @@ -5,9 +5,6 @@ #include #include #include -#include -#include -#include #include "../dn-vector.h" #include "../dn-simdhash.h" diff --git a/src/native/containers/simdhash-benchmark/all-measurements.h b/src/native/containers/simdhash-benchmark/all-measurements.h index 5b0dd90c8bd03..2e49927337a34 100644 --- a/src/native/containers/simdhash-benchmark/all-measurements.h +++ b/src/native/containers/simdhash-benchmark/all-measurements.h @@ -6,7 +6,9 @@ #ifndef MEASUREMENTS_IMPLEMENTATION #define MEASUREMENTS_IMPLEMENTATION 1 -#define INNER_COUNT 1024 * 32 +// If this is too large and libc's rand() is low quality (i.e. MSVC), +// initializing the data will take forever +#define INNER_COUNT 1024 * 16 #define BASELINE_SIZE 20480 static dn_simdhash_u32_ptr_t *random_u32s_hash; diff --git a/src/native/containers/simdhash-benchmark/benchmark.c b/src/native/containers/simdhash-benchmark/benchmark.c index 1eba949cece1f..320e43389cbed 100644 --- a/src/native/containers/simdhash-benchmark/benchmark.c +++ b/src/native/containers/simdhash-benchmark/benchmark.c @@ -6,12 +6,15 @@ #include #include #include -#include #include -#include -// WHY? +#ifdef _MSC_VER +#include +#else +#include +#include char *strcasestr(const char *haystack, const char *needle); +#endif #include "../dn-vector.h" #include "../dn-simdhash.h" @@ -41,6 +44,21 @@ dn_simdhash_assert_fail (const char *file, int line, const char *condition) { #define MTICKS_PER_SEC (10 * 1000 * 1000) int64_t get_100ns_ticks () { +#ifdef _MSC_VER + static LARGE_INTEGER freq; + static UINT64 start_time; + UINT64 cur_time; + LARGE_INTEGER value; + + if (!freq.QuadPart) { + QueryPerformanceFrequency(&freq); + QueryPerformanceCounter(&value); + start_time = value.QuadPart; + } + QueryPerformanceCounter(&value); + cur_time = value.QuadPart; + return (int64_t)((cur_time - start_time) * (double)MTICKS_PER_SEC / freq.QuadPart); +#else struct timespec ts; // FIXME: Use clock_monotonic for wall time instead? I think process time is what we want #ifdef __wasm @@ -49,6 +67,7 @@ int64_t get_100ns_ticks () { dn_simdhash_assert(clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts) == 0); #endif return ((int64_t)ts.tv_sec * MTICKS_PER_SEC + ts.tv_nsec / 100); +#endif } void init_measurements () { @@ -90,7 +109,11 @@ void foreach_measurement (const char *name, void *_info, void *_args) { uint8_t match = args->argc <= 1; for (int i = 1; i < args->argc; i++) { +#ifdef _MSC_VER + if (strstr(name, args->argv[i])) { +#else if (strcasestr(name, args->argv[i])) { +#endif match = 1; break; } diff --git a/src/native/containers/simdhash-benchmark/run-benchmark.ps1 b/src/native/containers/simdhash-benchmark/run-benchmark.ps1 new file mode 100755 index 0000000000000..eb640b81b9e75 --- /dev/null +++ b/src/native/containers/simdhash-benchmark/run-benchmark.ps1 @@ -0,0 +1,2 @@ +cl /O2 /std:c17 ./*.c ../dn-simdhash-u32-ptr.c ../dn-simdhash.c ../dn-vector.c ../dn-simdhash-string-ptr.c /DNO_CONFIG_H /DSIZEOF_VOID_P=8 /Fe:all-measurements.exe +./all-measurements.exe \ No newline at end of file