aboutsummaryrefslogtreecommitdiff
path: root/pw_checksum/crc32_perf_test.cc
blob: 2d96e20a79c968aa67856cff2531f847710501a5 (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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright 2022 The Pigweed Authors
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
// use this file except in compliance with the License. You may obtain a copy of
// the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations under
// the License.

#include <cstdint>
#include <string_view>

#include "pw_bytes/array.h"
#include "pw_checksum/crc32.h"
#include "pw_perf_test/perf_test.h"
#include "pw_span/span.h"

namespace pw::checksum {
namespace {

constexpr std::string_view kString =
    "In the beginning the Universe was created. This has made a lot of "
    "people very angry and been widely regarded as a bad move.";
constexpr auto kBytes = bytes::Array<1, 2, 3, 4, 5, 6, 7, 8, 9>();

void Crc32OneBitTest(perf_test::State& state, span<const std::byte> data) {
  while (state.KeepRunning()) {
    Crc32OneBit::Calculate(data);
  }
}

void Crc32FourBitTest(perf_test::State& state, span<const std::byte> data) {
  while (state.KeepRunning()) {
    Crc32FourBit::Calculate(data);
  }
}

void Crc32EightBitTest(perf_test::State& state, span<const std::byte> data) {
  while (state.KeepRunning()) {
    Crc32EightBit::Calculate(data);
  }
}

PW_PERF_TEST(CrcOneBitStringTest, Crc32OneBitTest, as_bytes(span(kString)));
PW_PERF_TEST(CrcFourBitStringTest, Crc32FourBitTest, as_bytes(span(kString)));
PW_PERF_TEST(CrcEightBitStringTest, Crc32EightBitTest, as_bytes(span(kString)));

PW_PERF_TEST(CrcOneBitBytesTest, Crc32OneBitTest, kBytes);
PW_PERF_TEST(CrcFourBitBytesTest, Crc32FourBitTest, kBytes);
PW_PERF_TEST(CrcEightBitBytesTest, Crc32EightBitTest, kBytes);

}  // namespace
}  // namespace pw::checksum