aboutsummaryrefslogtreecommitdiff
path: root/llvm/benchmarks/xxhash.cpp
blob: 429cbc0fa87d4b2e267bf029a028f93cf12fab08 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include "llvm/Support/xxhash.h"
#include "benchmark/benchmark.h"

#include <memory>

static uint32_t xorshift(uint32_t State) {
  State ^= State << 13;
  State ^= State >> 17;
  State ^= State << 5;
  return State;
}

static void BM_xxh3_64bits(benchmark::State &State) {
  std::unique_ptr<uint32_t[]> Data(new uint32_t[State.range(0) / 4]);

  uint32_t Prev = 0xcafebabe;
  for (int64_t I = 0; I < State.range(0) / 4; I++)
    Data[I] = Prev = xorshift(Prev);

  llvm::ArrayRef DataRef =
      llvm::ArrayRef(reinterpret_cast<uint8_t *>(Data.get()), State.range(0));

  for (auto _ : State)
    llvm::xxh3_64bits(DataRef);
}

BENCHMARK(BM_xxh3_64bits)->Arg(32)->Arg(512)->Arg(64 * 1024)->Arg(1024 * 1024);

BENCHMARK_MAIN();