Skip to content

Commit

Permalink
Make it possible to build benchmark suite using MSVC
Browse files Browse the repository at this point in the history
  • Loading branch information
kg committed Apr 15, 2024
1 parent 1f2b89f commit 5083f40
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/native/containers/dn-simdhash-ght-compatible.c
Original file line number Diff line number Diff line change
@@ -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 <config.h>
#endif
#include "dn-simdhash.h"

#include "dn-simdhash-utils.h"
Expand Down
2 changes: 2 additions & 0 deletions src/native/containers/dn-simdhash-ptr-ptr.c
Original file line number Diff line number Diff line change
@@ -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 <config.h>
#endif
#include "dn-simdhash.h"

#include "dn-simdhash-utils.h"
Expand Down
1 change: 1 addition & 0 deletions src/native/containers/dn-simdhash.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#ifndef __DN_SIMDHASH_H__
#define __DN_SIMDHASH_H__

#include <stdint.h>
#include "dn-utils.h"
#include "dn-allocator.h"

Expand Down
3 changes: 0 additions & 3 deletions src/native/containers/simdhash-benchmark/all-measurements.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
#include <inttypes.h>
#include <stdio.h>
#include <assert.h>
#include <time.h>
#include <sys/time.h>
#include <strings.h>

#include "../dn-vector.h"
#include "../dn-simdhash.h"
Expand Down
4 changes: 3 additions & 1 deletion src/native/containers/simdhash-benchmark/all-measurements.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
29 changes: 26 additions & 3 deletions src/native/containers/simdhash-benchmark/benchmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
#include <stdio.h>
#include <assert.h>
#include <time.h>
#include <sys/time.h>
#include <string.h>
#include <strings.h>

// WHY?
#ifdef _MSC_VER
#include <windows.h>
#else
#include <sys/time.h>
#include <strings.h>
char *strcasestr(const char *haystack, const char *needle);
#endif

#include "../dn-vector.h"
#include "../dn-simdhash.h"
Expand Down Expand Up @@ -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
Expand All @@ -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 () {
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions src/native/containers/simdhash-benchmark/run-benchmark.ps1
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 5083f40

Please sign in to comment.