Created
December 15, 2021 04:31
-
-
Save KungFuJesus/e50c717e9853ae6be4ebebb24709c532 to your computer and use it in GitHub Desktop.
This file contains hidden or 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> | |
#include <stdio.h> | |
#include <stdint.h> | |
#include "zbuild.h" | |
#include <benchmark/benchmark.h> | |
#define MAX_RANDOM_INTS (8192*8192 + 5) | |
static uint32_t *random_ints = NULL; | |
/* adler32 */ | |
extern "C" uint32_t adler32_c(uint32_t adler, const unsigned char *buf, size_t len); | |
#ifdef X86_SSSE3_ADLER32 | |
extern "C" uint32_t adler32_ssse3(uint32_t adler, const unsigned char *buf, size_t len); | |
#endif | |
#ifdef X86_AVX2_ADLER32 | |
extern "C" uint32_t adler32_avx2(uint32_t adler, const unsigned char *buf, size_t len); | |
#endif | |
#ifdef X86_AVX512_ADLER32 | |
extern "C" uint32_t adler32_avx512(uint32_t adler, const unsigned char *buf, size_t len); | |
#endif | |
#ifdef X86_AVX512VNNI_ADLER32 | |
extern "C" uint32_t adler32_avx512_vnni(uint32_t adler, const unsigned char *buf, size_t len); | |
#endif | |
static void adler32_c_bench(benchmark::State& state) { | |
int32_t j = 0; | |
uint32_t a = 0; | |
while (state.KeepRunning()) { | |
uint32_t hash = adler32_c(a, (const unsigned char *)random_ints, j * sizeof(uint32_t)); | |
benchmark::DoNotOptimize(hash); | |
if (++j >= MAX_RANDOM_INTS) { j = 0;}; | |
} | |
} | |
BENCHMARK(adler32_c_bench); | |
#ifdef X86_SSSE3_ADLER32 | |
static void adler32_ssse3_bench(benchmark::State& state) { | |
int32_t j = 0; | |
uint32_t a = 0; | |
while (state.KeepRunning()) { | |
uint32_t hash = adler32_ssse3(a, (const unsigned char *)random_ints, j * sizeof(uint32_t)); | |
benchmark::DoNotOptimize(hash); | |
if (++j >= MAX_RANDOM_INTS) {j = 0; }; | |
} | |
} | |
BENCHMARK(adler32_ssse3_bench); | |
#endif | |
#ifdef X86_AVX2_ADLER32 | |
static void adler32_avx2_bench(benchmark::State& state) { | |
int32_t j = 0; | |
uint32_t a = 0; | |
while (state.KeepRunning()) { | |
uint32_t hash = adler32_avx2(a, (const unsigned char *)random_ints, j * sizeof(uint32_t)); | |
benchmark::DoNotOptimize(hash); | |
if (++j >= MAX_RANDOM_INTS) {j = 0; }; | |
} | |
} | |
BENCHMARK(adler32_avx2_bench); | |
#endif | |
#ifdef X86_AVX512_ADLER32 | |
static void adler32_avx512_bench(benchmark::State& state) { | |
int32_t j = 0; | |
uint32_t a = 0; | |
while (state.KeepRunning()) { | |
uint32_t hash = adler32_avx512(a, (const unsigned char *)random_ints, j * sizeof(uint32_t)); | |
benchmark::DoNotOptimize(hash); | |
if (++j >= MAX_RANDOM_INTS) {j = 0; }; | |
} | |
} | |
BENCHMARK(adler32_avx512_bench); | |
#endif | |
#ifdef X86_AVX512VNNI_ADLER32 | |
static void adler32_avx512vnni_bench(benchmark::State& state) { | |
int32_t j = 0; | |
uint32_t a = 0; | |
while (state.KeepRunning()) { | |
uint32_t hash = adler32_avx512_vnni(a, (const unsigned char *)random_ints, j * sizeof(uint32_t)); | |
benchmark::DoNotOptimize(hash); | |
if (++j >= MAX_RANDOM_INTS) {j = 0;}; | |
} | |
} | |
BENCHMARK(adler32_avx512vnni_bench); | |
#endif | |
int main(int argc, char** argv) | |
{ | |
int32_t random_ints_size = MAX_RANDOM_INTS * sizeof(uint32_t); | |
random_ints = (uint32_t *)malloc(random_ints_size); | |
for (int32_t i = 0; i < MAX_RANDOM_INTS; i++) { | |
random_ints[i] = rand(); | |
} | |
::benchmark::Initialize(&argc, argv); | |
::benchmark::RunSpecifiedBenchmarks(); | |
free(random_ints); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment