From f617f9e266812cf0ff58bcc693e097d19310ebcb Mon Sep 17 00:00:00 2001 From: Brian Barcenas Date: Sat, 10 Dec 2022 01:15:29 +0000 Subject: [PATCH] pw_checksum: Added CRC16 performance testing Change-Id: I8add879e4ba63ee21400a7a37c7326dc00be2700 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/123173 Pigweed-Auto-Submit: Wyatt Hepler Reviewed-by: Wyatt Hepler Commit-Queue: Auto-Submit --- pw_checksum/BUILD.bazel | 9 ++++++ pw_checksum/BUILD.gn | 14 +++++++++- pw_checksum/crc16_ccitt_perf_test.cc | 41 ++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 pw_checksum/crc16_ccitt_perf_test.cc diff --git a/pw_checksum/BUILD.bazel b/pw_checksum/BUILD.bazel index 3e748ca4c2..adf33dd532 100644 --- a/pw_checksum/BUILD.bazel +++ b/pw_checksum/BUILD.bazel @@ -75,3 +75,12 @@ pw_cc_perf_test( "//pw_bytes", ], ) + +pw_cc_perf_test( + name = "crc16_perf_test", + srcs = ["crc16_ccitt_perf_test.cc"], + deps = [ + ":pw_checksum", + "//pw_bytes", + ], +) diff --git a/pw_checksum/BUILD.gn b/pw_checksum/BUILD.gn index 79a113f70a..450d701548 100644 --- a/pw_checksum/BUILD.gn +++ b/pw_checksum/BUILD.gn @@ -104,8 +104,20 @@ pw_perf_test("crc32_perf_tests") { sources = [ "crc32_perf_test.cc" ] } +pw_perf_test("crc16_perf_tests") { + enable_if = pw_perf_test_TIMER_INTERFACE_BACKEND != "" + deps = [ + ":pw_checksum", + dir_pw_bytes, + ] + sources = [ "crc16_ccitt_perf_test.cc" ] +} + group("perf_tests") { - deps = [ ":crc32_perf_tests" ] + deps = [ + ":crc16_perf_tests", + ":crc32_perf_tests", + ] } pw_size_diff("size_report") { diff --git a/pw_checksum/crc16_ccitt_perf_test.cc b/pw_checksum/crc16_ccitt_perf_test.cc new file mode 100644 index 0000000000..0ec9b0582c --- /dev/null +++ b/pw_checksum/crc16_ccitt_perf_test.cc @@ -0,0 +1,41 @@ +// 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 + +#include "pw_bytes/array.h" +#include "pw_checksum/crc16_ccitt.h" +#include "pw_perf_test/perf_test.h" +#include "pw_span/internal/span_impl.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::Initialized<1000>([](size_t i) { return i; }); + +void CcittCalculationTest(span input) { + Crc16Ccitt::Calculate(input); +} + +PW_PERF_TEST_SIMPLE(CcittCalculationBytes, CcittCalculationTest, kBytes); +PW_PERF_TEST_SIMPLE(CcittCalculationString, + CcittCalculationTest, + as_bytes(span(kString))); + +} // namespace +} // namespace pw::checksum