Project
Loading...
Searching...
No Matches
benchmark_BigEndian.cxx
Go to the documentation of this file.
1// Copyright 2019-2026 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
12#include "Framework/BigEndian.h"
13#include <benchmark/benchmark.h>
14#include <cstdint>
15#include <cstdlib>
16#include <vector>
17
18using namespace o2::framework;
19
20static void BM_BigEndianCopyUInt16(benchmark::State& state)
21{
22 auto const bytes = static_cast<size_t>(state.range(0));
23 int const count = bytes / sizeof(uint16_t);
24 std::vector<uint16_t> src(count, 0xCAFE);
25 auto* dest = static_cast<uint16_t*>(std::aligned_alloc(64, bytes));
26 for (auto _ : state) {
27 bigEndianCopy(dest, src.data(), count, sizeof(uint16_t));
28 benchmark::DoNotOptimize(dest);
29 }
30 state.SetBytesProcessed(static_cast<int64_t>(state.iterations()) * bytes);
31 std::free(dest);
32}
33BENCHMARK(BM_BigEndianCopyUInt16)->RangeMultiplier(2)->Range(32000, 512000);
34
35static void BM_BigEndianCopyUInt32(benchmark::State& state)
36{
37 auto const bytes = static_cast<size_t>(state.range(0));
38 int const count = bytes / sizeof(uint32_t);
39 std::vector<uint32_t> src(count, 0xDEADBEEF);
40 auto* dest = static_cast<uint32_t*>(std::aligned_alloc(64, bytes));
41 for (auto _ : state) {
42 bigEndianCopy(dest, src.data(), count, sizeof(uint32_t));
43 benchmark::DoNotOptimize(dest);
44 }
45 state.SetBytesProcessed(static_cast<int64_t>(state.iterations()) * bytes);
46 std::free(dest);
47}
48BENCHMARK(BM_BigEndianCopyUInt32)->RangeMultiplier(2)->Range(32000, 512000);
49
50static void BM_BigEndianCopyUInt64(benchmark::State& state)
51{
52 auto const bytes = static_cast<size_t>(state.range(0));
53 int const count = bytes / sizeof(uint64_t);
54 std::vector<uint64_t> src(count, 0x0123456789ABCDEFULL);
55 auto* dest = static_cast<uint64_t*>(std::aligned_alloc(64, bytes));
56 for (auto _ : state) {
57 bigEndianCopy(dest, src.data(), count, sizeof(uint64_t));
58 benchmark::DoNotOptimize(dest);
59 }
60 state.SetBytesProcessed(static_cast<int64_t>(state.iterations()) * bytes);
61 std::free(dest);
62}
63BENCHMARK(BM_BigEndianCopyUInt64)->RangeMultiplier(2)->Range(32000, 512000);
64
benchmark::State & state
BENCHMARK(BM_BigEndianCopyUInt16) -> RangeMultiplier(2) ->Range(32000, 512000)
BENCHMARK_MAIN()
GLenum src
Definition glcorearb.h:1767
GLint GLsizei count
Definition glcorearb.h:399
Defining ITS Vertex explicitly as messageable.
Definition Cartesian.h:288
void bigEndianCopy(void *dest, const void *src, int count, size_t typeSize)
Definition BigEndian.h:26