Skip to content

Commit

Permalink
benchmark prival from string (#379)
Browse files Browse the repository at this point in the history
Add a benchmark test for stumpless_prival_from_string.

This fixes #378 which can be referenced for more information.
  • Loading branch information
kirubaspace authored Oct 16, 2023
1 parent fc7b4d3 commit 67cf413
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
44 changes: 44 additions & 0 deletions test/performance/priority.cpp
Original file line number Diff line number Diff line change
@@ -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 <benchmark/benchmark.h>
#include <stumpless.h>
#include "test/helper/memory_counter.hpp"
#include <string>

NEW_MEMORY_COUNTER( prival_from_string )

static void PrivalFromString(benchmark::State& state) {
// Create a list of priorities.
std::vector<std::string> 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);

0 comments on commit 67cf413

Please sign in to comment.