From 67cf413f860005995241c3984222edf3ebb80943 Mon Sep 17 00:00:00 2001 From: kirubaspace <54947026+kirubaspace@users.noreply.github.com> Date: Mon, 16 Oct 2023 21:04:50 +0530 Subject: [PATCH] benchmark prival from string (#379) Add a benchmark test for stumpless_prival_from_string. This fixes #378 which can be referenced for more information. --- CMakeLists.txt | 6 ++++- test/performance/priority.cpp | 44 +++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 test/performance/priority.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 997d2e185..5279f2f6f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1014,7 +1014,11 @@ add_custom_target(examples # performance tests add_performance_test(element - SOURCES test/performance/element.cpp +SOURCES test/performance/element.cpp +) + +add_performance_test(priority +SOURCES test/performance/priority.cpp ) add_performance_test(entry diff --git a/test/performance/priority.cpp b/test/performance/priority.cpp new file mode 100644 index 000000000..523126344 --- /dev/null +++ b/test/performance/priority.cpp @@ -0,0 +1,44 @@ +// SPDX-License-Identifier: Apache-2.0 + +/* + * Copyright 2020-2022 Joel E. Anderson + * + * 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 + * + * http://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 +#include "test/helper/memory_counter.hpp" +#include + +NEW_MEMORY_COUNTER( prival_from_string ) + +static void PrivalFromString(benchmark::State& state) { + // Create a list of priorities. + std::vector priority_list = {"191", "user.emerg", "uucp.err", "local7.debug"}; + + INIT_MEMORY_COUNTER( prival_from_string ); + + // Measure the time it takes to call the function. + for (auto _ : state) { + for (const auto& priority : priority_list) { + int result = stumpless_prival_from_string(priority.c_str()); + if ( result< 0) { + state.SkipWithError("could not get the prival from the string"); + } + } + } + SET_STATE_COUNTERS( state, prival_from_string ); +} + +BENCHMARK(PrivalFromString); \ No newline at end of file