-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from m-peko/add-benchmark
Add benchmark
- Loading branch information
Showing
14 changed files
with
709 additions
and
11 deletions.
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
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
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,4 @@ | ||
cmake_minimum_required (VERSION 3.8) | ||
|
||
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/src) | ||
add_subdirectory (src) |
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,33 @@ | ||
cmake_minimum_required (VERSION 3.8) | ||
|
||
# Use bitflags's include directories + Google Benchmark include directories | ||
include_directories ( | ||
${PROJECT_SOURCE_DIR}/include/ | ||
${GOOGLEBENCH_INCLUDE} | ||
) | ||
|
||
link_directories ( | ||
${GOOGLEBENCH_LIBRARY} | ||
) | ||
|
||
# Link against GoogleBenchmark and bitflags | ||
link_libraries ( | ||
benchmark | ||
bitflags | ||
) | ||
|
||
add_custom_target (benchmarks) | ||
|
||
macro (create_benchmark benchmark_name) | ||
string (REPLACE "/" "_" binary_name ${benchmark_name}) | ||
set (binary_name "${binary_name}_benchmark") | ||
add_executable (${binary_name} EXCLUDE_FROM_ALL "${benchmark_name}_benchmark.cpp") | ||
add_test (${benchmark_name} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${binary_name}) | ||
add_dependencies (benchmarks ${binary_name}) | ||
endmacro () | ||
|
||
# Benchmarks | ||
|
||
create_benchmark (bitset) | ||
create_benchmark (bitflags) | ||
create_benchmark (raw_bitflags) |
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,174 @@ | ||
/* | ||
* Copyright (c) 2020, Marin Peko | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are | ||
* met: | ||
* | ||
* * Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* * Redistributions in binary form must reproduce the above | ||
* copyright notice, this list of conditions and the following disclaimer | ||
* in the documentation and/or other materials provided with the | ||
* distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
*/ | ||
|
||
#include <benchmark/benchmark.h> | ||
#include <bitflags/bitflags.hpp> | ||
|
||
BEGIN_BITFLAGS(Flags) | ||
FLAG(none) | ||
FLAG(flag_a) | ||
FLAG(flag_b) | ||
FLAG(flag_c) | ||
END_BITFLAGS(Flags) | ||
|
||
void OperatorNot(benchmark::State& state) { | ||
Flags flags; | ||
|
||
for (auto _ : state) { | ||
flags = ~Flags::none; | ||
benchmark::DoNotOptimize(flags); | ||
} | ||
} | ||
|
||
BENCHMARK(OperatorNot); | ||
|
||
void OperatorAnd(benchmark::State& state) { | ||
Flags flags; | ||
|
||
for (auto _ : state) { | ||
flags &= Flags::flag_a; | ||
benchmark::DoNotOptimize(flags); | ||
} | ||
} | ||
|
||
BENCHMARK(OperatorAnd); | ||
|
||
void OperatorOr(benchmark::State& state) { | ||
Flags flags; | ||
|
||
for (auto _ : state) { | ||
flags |= Flags::flag_a; | ||
benchmark::DoNotOptimize(flags); | ||
} | ||
} | ||
|
||
BENCHMARK(OperatorOr); | ||
|
||
void OperatorXor(benchmark::State& state) { | ||
Flags flags; | ||
|
||
for (auto _ : state) { | ||
flags ^= Flags::flag_a; | ||
benchmark::DoNotOptimize(flags); | ||
} | ||
} | ||
|
||
BENCHMARK(OperatorXor); | ||
|
||
void Empty(benchmark::State& state) { | ||
Flags flags; | ||
|
||
for (auto _ : state) { | ||
flags = Flags::empty(); | ||
benchmark::DoNotOptimize(flags); | ||
} | ||
} | ||
|
||
BENCHMARK(Empty); | ||
|
||
void All(benchmark::State& state) { | ||
Flags flags; | ||
|
||
for (auto _ : state) { | ||
flags = Flags::all(); | ||
benchmark::DoNotOptimize(flags); | ||
} | ||
} | ||
|
||
BENCHMARK(All); | ||
|
||
void IsEmpty(benchmark::State& state) { | ||
Flags flags; | ||
|
||
for (auto _ : state) { | ||
[[maybe_unused]] bool is_empty = flags.is_empty(); | ||
benchmark::DoNotOptimize(flags); | ||
benchmark::DoNotOptimize(is_empty); | ||
} | ||
} | ||
|
||
BENCHMARK(IsEmpty); | ||
|
||
void IsAll(benchmark::State& state) { | ||
Flags flags; | ||
|
||
for (auto _ : state) { | ||
[[maybe_unused]] bool is_all = flags.is_all(); | ||
benchmark::DoNotOptimize(flags); | ||
benchmark::DoNotOptimize(is_all); | ||
} | ||
} | ||
|
||
BENCHMARK(IsAll); | ||
|
||
void Set(benchmark::State& state) { | ||
Flags flags; | ||
|
||
for (auto _ : state) { | ||
flags.set(Flags::flag_a); | ||
benchmark::DoNotOptimize(flags); | ||
} | ||
} | ||
|
||
BENCHMARK(Set); | ||
|
||
void Remove(benchmark::State& state) { | ||
Flags flags; | ||
|
||
for (auto _ : state) { | ||
flags.remove(Flags::flag_a); | ||
benchmark::DoNotOptimize(flags); | ||
} | ||
} | ||
|
||
BENCHMARK(Remove); | ||
|
||
void Toggle(benchmark::State& state) { | ||
Flags flags; | ||
|
||
for (auto _ : state) { | ||
flags.toggle(Flags::flag_a); | ||
benchmark::DoNotOptimize(flags); | ||
} | ||
} | ||
|
||
BENCHMARK(Toggle); | ||
|
||
void Clear(benchmark::State& state) { | ||
Flags flags; | ||
|
||
for (auto _ : state) { | ||
flags.clear(); | ||
benchmark::DoNotOptimize(flags); | ||
} | ||
} | ||
|
||
BENCHMARK(Clear); | ||
|
||
BENCHMARK_MAIN(); |
Oops, something went wrong.