mirror of
https://github.com/BlackMATov/flat.hpp.git
synced 2025-12-13 01:36:27 +07:00
add simple foreach bench
This commit is contained in:
8
scripts/bench_map_foreach.sh
Executable file
8
scripts/bench_map_foreach.sh
Executable file
@@ -0,0 +1,8 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
BUILD_DIR=`dirname "$BASH_SOURCE"`/../build
|
||||
cd $BUILD_DIR
|
||||
|
||||
./unbench/flat.hpp.unbench --benchmark_filter=_map_foreach --benchmark_format=csv > benchmark_map_foreach.csv
|
||||
../scripts/bench_drawer.py -f benchmark_map_foreach.csv
|
||||
8
scripts/bench_set_foreach.sh
Executable file
8
scripts/bench_set_foreach.sh
Executable file
@@ -0,0 +1,8 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
BUILD_DIR=`dirname "$BASH_SOURCE"`/../build
|
||||
cd $BUILD_DIR
|
||||
|
||||
./unbench/flat.hpp.unbench --benchmark_filter=_set_foreach --benchmark_format=csv > benchmark_set_foreach.csv
|
||||
../scripts/bench_drawer.py -f benchmark_set_foreach.csv
|
||||
94
unbench/map_foreach_bench.cpp
Normal file
94
unbench/map_foreach_bench.cpp
Normal file
@@ -0,0 +1,94 @@
|
||||
/*******************************************************************************
|
||||
* This file is part of the "https://github.com/blackmatov/flat.hpp"
|
||||
* For conditions of distribution and use, see copyright notice in LICENSE.md
|
||||
* Copyright (C) 2019, by Matvey Cherevko (blackmatov@gmail.com)
|
||||
******************************************************************************/
|
||||
|
||||
#include "bench_base.hpp"
|
||||
using namespace flat_hpp_unbench;
|
||||
|
||||
#include <flat_hpp/flat_map.hpp>
|
||||
using namespace flat_hpp;
|
||||
|
||||
#ifdef BOOST_CONTAINER_FOUND
|
||||
# include <boost/container/flat_map.hpp>
|
||||
#endif
|
||||
|
||||
namespace
|
||||
{
|
||||
template < typename Value >
|
||||
void flat_map_foreach(benchmark::State& state) {
|
||||
std::vector<std::pair<int,int>> v;
|
||||
generate_random_vector(state.range(), v);
|
||||
flat_map<int, Value> s(v.begin(), v.end());
|
||||
for ( auto _ : state ) {
|
||||
int acc = 0;
|
||||
for ( const auto& e : s ) {
|
||||
acc += e.second.x;
|
||||
}
|
||||
benchmark::DoNotOptimize(acc);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef BOOST_CONTAINER_FOUND
|
||||
template < typename Value >
|
||||
void boost_flat_map_foreach(benchmark::State& state) {
|
||||
std::vector<std::pair<int,int>> v;
|
||||
generate_random_vector(state.range(), v);
|
||||
boost::container::flat_map<int, Value> s(v.begin(), v.end());
|
||||
for ( auto _ : state ) {
|
||||
int acc = 0;
|
||||
for ( const auto& e : s ) {
|
||||
acc += e.second.x;
|
||||
}
|
||||
benchmark::DoNotOptimize(acc);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
template < typename Value >
|
||||
void std_map_foreach(benchmark::State& state) {
|
||||
std::vector<std::pair<int,int>> v;
|
||||
generate_random_vector(state.range(), v);
|
||||
std::map<int, Value> s(v.begin(), v.end());
|
||||
for ( auto _ : state ) {
|
||||
int acc = 0;
|
||||
for ( const auto& e : s ) {
|
||||
acc += e.second.x;
|
||||
}
|
||||
benchmark::DoNotOptimize(acc);
|
||||
}
|
||||
}
|
||||
|
||||
template < typename Value >
|
||||
void std_unordered_map_foreach(benchmark::State& state) {
|
||||
std::vector<std::pair<int,int>> v;
|
||||
generate_random_vector(state.range(), v);
|
||||
std::unordered_map<int, Value> s(v.begin(), v.end());
|
||||
for ( auto _ : state ) {
|
||||
int acc = 0;
|
||||
for ( const auto& e : s ) {
|
||||
acc += e.second.x;
|
||||
}
|
||||
benchmark::DoNotOptimize(acc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BENCHMARK_TEMPLATE(flat_map_foreach, vec4)
|
||||
->ComputeStatistics("min", min_bench_statistics)
|
||||
->DenseRange(1,401,50);
|
||||
|
||||
#ifdef BOOST_CONTAINER_FOUND
|
||||
BENCHMARK_TEMPLATE(boost_flat_map_foreach, vec4)
|
||||
->ComputeStatistics("min", min_bench_statistics)
|
||||
->DenseRange(1,401,50);
|
||||
#endif
|
||||
|
||||
BENCHMARK_TEMPLATE(std_map_foreach, vec4)
|
||||
->ComputeStatistics("min", min_bench_statistics)
|
||||
->DenseRange(1,401,50);
|
||||
|
||||
BENCHMARK_TEMPLATE(std_unordered_map_foreach, vec4)
|
||||
->ComputeStatistics("min", min_bench_statistics)
|
||||
->DenseRange(1,401,50);
|
||||
94
unbench/set_foreach_bench.cpp
Normal file
94
unbench/set_foreach_bench.cpp
Normal file
@@ -0,0 +1,94 @@
|
||||
/*******************************************************************************
|
||||
* This file is part of the "https://github.com/blackmatov/flat.hpp"
|
||||
* For conditions of distribution and use, see copyright notice in LICENSE.md
|
||||
* Copyright (C) 2019, by Matvey Cherevko (blackmatov@gmail.com)
|
||||
******************************************************************************/
|
||||
|
||||
#include "bench_base.hpp"
|
||||
using namespace flat_hpp_unbench;
|
||||
|
||||
#include <flat_hpp/flat_set.hpp>
|
||||
using namespace flat_hpp;
|
||||
|
||||
#ifdef BOOST_CONTAINER_FOUND
|
||||
# include <boost/container/flat_set.hpp>
|
||||
#endif
|
||||
|
||||
namespace
|
||||
{
|
||||
template < typename Value >
|
||||
void flat_set_foreach(benchmark::State& state) {
|
||||
std::vector<int> v;
|
||||
generate_random_vector(state.range(), v);
|
||||
flat_set<Value> s(v.begin(), v.end());
|
||||
for ( auto _ : state ) {
|
||||
int acc = 0;
|
||||
for ( const auto& e : s ) {
|
||||
acc += e.x;
|
||||
}
|
||||
benchmark::DoNotOptimize(acc);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef BOOST_CONTAINER_FOUND
|
||||
template < typename Value >
|
||||
void boost_flat_set_foreach(benchmark::State& state) {
|
||||
std::vector<int> v;
|
||||
generate_random_vector(state.range(), v);
|
||||
boost::container::flat_set<Value> s(v.begin(), v.end());
|
||||
for ( auto _ : state ) {
|
||||
int acc = 0;
|
||||
for ( const auto& e : s ) {
|
||||
acc += e.x;
|
||||
}
|
||||
benchmark::DoNotOptimize(acc);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
template < typename Value >
|
||||
void std_set_foreach(benchmark::State& state) {
|
||||
std::vector<int> v;
|
||||
generate_random_vector(state.range(), v);
|
||||
std::set<Value> s(v.begin(), v.end());
|
||||
for ( auto _ : state ) {
|
||||
int acc = 0;
|
||||
for ( const auto& e : s ) {
|
||||
acc += e.x;
|
||||
}
|
||||
benchmark::DoNotOptimize(acc);
|
||||
}
|
||||
}
|
||||
|
||||
template < typename Value >
|
||||
void std_unordered_set_foreach(benchmark::State& state) {
|
||||
std::vector<int> v;
|
||||
generate_random_vector(state.range(), v);
|
||||
std::unordered_set<Value> s(v.begin(), v.end());
|
||||
for ( auto _ : state ) {
|
||||
int acc = 0;
|
||||
for ( const auto& e : s ) {
|
||||
acc += e.x;
|
||||
}
|
||||
benchmark::DoNotOptimize(acc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BENCHMARK_TEMPLATE(flat_set_foreach, vec4)
|
||||
->ComputeStatistics("min", min_bench_statistics)
|
||||
->DenseRange(1,401,50);
|
||||
|
||||
#ifdef BOOST_CONTAINER_FOUND
|
||||
BENCHMARK_TEMPLATE(boost_flat_set_foreach, vec4)
|
||||
->ComputeStatistics("min", min_bench_statistics)
|
||||
->DenseRange(1,401,50);
|
||||
#endif
|
||||
|
||||
BENCHMARK_TEMPLATE(std_set_foreach, vec4)
|
||||
->ComputeStatistics("min", min_bench_statistics)
|
||||
->DenseRange(1,401,50);
|
||||
|
||||
BENCHMARK_TEMPLATE(std_unordered_set_foreach, vec4)
|
||||
->ComputeStatistics("min", min_bench_statistics)
|
||||
->DenseRange(1,401,50);
|
||||
Reference in New Issue
Block a user