-
Notifications
You must be signed in to change notification settings - Fork 340
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a benchmark test for stumpless_prival_from_string. This fixes #378 which can be referenced for more information.
- Loading branch information
1 parent
fc7b4d3
commit 67cf413
Showing
2 changed files
with
49 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |