Skip to content

Commit

Permalink
fixed make error for macosx (#81)
Browse files Browse the repository at this point in the history
* fixed make error for macosx

* fixed clock_gettime issue for macosx
  • Loading branch information
inspire365 authored Feb 1, 2021
1 parent 76fd8b3 commit 2a93d78
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/redis-roaring.c
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ int RBitFlip(RedisModuleCtx* ctx, RedisModuleString** argv, int argc) {
}

bool should_free = false;
Bitmap* bitmap;
Bitmap* bitmap = NULL;
if (srctype == REDISMODULE_KEYTYPE_EMPTY) {
// "non-existent keys [...] are considered as a stream of zero bytes up to the length of the longest string"
bitmap = bitmap_alloc();
Expand Down
29 changes: 27 additions & 2 deletions tests/performance.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
#include "hiredis.h"
#include "benchmarks/numbersfromtextfiles.h"

#ifdef __MACH__
#include <mach/clock.h>
#include <mach/mach.h>
#endif


/*
* macros
*/
Expand Down Expand Up @@ -78,16 +84,35 @@ void print_header() {
print("| %12s |\n", "------------");
}

int clock_gettime_local(struct timespec *a) {
int err = 0;
//https://gist.github.com/jbenet/1087739
#ifdef __MACH__ // OS X does not have clock_gettime, use clock_get_time
clock_serv_t cclock;
mach_timespec_t mts;
host_get_clock_service(mach_host_self(), REALTIME_CLOCK, &cclock);
clock_get_time(cclock, &mts);
mach_port_deallocate(mach_task_self(), cclock);
a->tv_sec = mts.tv_sec;
a->tv_nsec = mts.tv_nsec;
#else
err = clock_gettime(CLOCK_MONOTONIC, a);
#endif
return err;
}

void static inline timer(Statistics* statistics) {
if (!statistics->ticking) {
clock_gettime(CLOCK_MONOTONIC, &statistics->start);
//clock_gettime(CLOCK_MONOTONIC, &statistics->start);
clock_gettime_local(&statistics->start);
statistics->ticking = true;
return;
}
statistics->ticking = false;

struct timespec end;
clock_gettime(CLOCK_MONOTONIC, &end);
//clock_gettime(CLOCK_MONOTONIC, &end);
clock_gettime_local(&end);
double ns = (end.tv_sec - statistics->start.tv_sec) * 1000000000UL + (end.tv_nsec - statistics->start.tv_nsec);

// https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Online_algorithm
Expand Down

0 comments on commit 2a93d78

Please sign in to comment.