Created
April 8, 2024 11:06
-
-
Save panzhongxian/c7dd59bdafb42435c9701df6c90813fc to your computer and use it in GitHub Desktop.
Test redis loop performance in hyperloglog.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdint.h> | |
#define HLL_REGISTERS 16384 | |
#define HLL_BITS 6 | |
/* Compute the register histogram in the dense representation. */ | |
void hllDenseRegHisto(uint8_t* registers, int* reghisto) { | |
int j; | |
/* Redis default is to use 16384 registers 6 bits each. The code works | |
* with other values by modifying the defines, but for our target value | |
* we take a faster path with unrolled loops. */ | |
uint8_t* r = registers; | |
#ifndef SIMPLIFIED | |
unsigned long r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13, r14, | |
r15; | |
for (j = 0; j < 1024; j++) { | |
/* Handle 16 registers per iteration. */ | |
r0 = r[0] & 63; | |
r1 = (r[0] >> 6 | r[1] << 2) & 63; | |
r2 = (r[1] >> 4 | r[2] << 4) & 63; | |
r3 = (r[2] >> 2) & 63; | |
r4 = r[3] & 63; | |
r5 = (r[3] >> 6 | r[4] << 2) & 63; | |
r6 = (r[4] >> 4 | r[5] << 4) & 63; | |
r7 = (r[5] >> 2) & 63; | |
r8 = r[6] & 63; | |
r9 = (r[6] >> 6 | r[7] << 2) & 63; | |
r10 = (r[7] >> 4 | r[8] << 4) & 63; | |
r11 = (r[8] >> 2) & 63; | |
r12 = r[9] & 63; | |
r13 = (r[9] >> 6 | r[10] << 2) & 63; | |
r14 = (r[10] >> 4 | r[11] << 4) & 63; | |
r15 = (r[11] >> 2) & 63; | |
reghisto[r0]++; | |
reghisto[r1]++; | |
reghisto[r2]++; | |
reghisto[r3]++; | |
reghisto[r4]++; | |
reghisto[r5]++; | |
reghisto[r6]++; | |
reghisto[r7]++; | |
reghisto[r8]++; | |
reghisto[r9]++; | |
reghisto[r10]++; | |
reghisto[r11]++; | |
reghisto[r12]++; | |
reghisto[r13]++; | |
reghisto[r14]++; | |
reghisto[r15]++; | |
r += 12; | |
} | |
#else | |
unsigned long r0, r1, r2, r3; | |
for (j = 0; j < 4096; j++) { | |
r0 = r[0] & 63; | |
r1 = (r[0] >> 6 | r[1] << 2) & 63; | |
r2 = (r[1] >> 4 | r[2] << 4) & 63; | |
r3 = (r[2] >> 2) & 63; | |
reghisto[r0]++; | |
reghisto[r1]++; | |
reghisto[r2]++; | |
reghisto[r3]++; | |
r += 3; | |
} | |
#endif | |
} | |
int main() { | |
uint8_t registers[HLL_REGISTERS]; | |
int reghisto[64] = {0}; | |
for (int i = 0; i < 1000000; i++) { | |
hllDenseRegHisto(registers, reghisto); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment