Commit 9dbba377 authored by Armin Sobhani's avatar Armin Sobhani
Browse files

add sequence_host benchmark using Google benchmark

parent 77b1cfe0
[requires]
google-benchmark/1.4.1@mpusz/stable
[generators]
cmake
\ No newline at end of file
......@@ -7,6 +7,10 @@
#
# ----------------------------------------------------------------------------
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
set(CONAN_DISABLE_CHECK_COMPILER true)
conan_basic_setup()
include_directories(../include)
set(BOOST_COMPONENTS system timer chrono program_options)
......@@ -17,6 +21,7 @@ endif()
find_package(Boost 1.61 REQUIRED COMPONENTS ${BOOST_COMPONENTS})
set(BENCHMARKS
sequence_host
stl_random_sequence
stl_reverse_complement
)
......@@ -24,7 +29,7 @@ set(BENCHMARKS
foreach(BENCHMARK ${BENCHMARKS})
set(PERF_TARGET perf_${BENCHMARK})
add_executable(${PERF_TARGET} perf_${BENCHMARK}.cpp)
target_link_libraries(${PERF_TARGET} ${Boost_LIBRARIES})
target_link_libraries(${PERF_TARGET} ${Boost_LIBRARIES} ${CONAN_LIBS})
endforeach()
if(${BOOST_BIOSEQ_BUILD_OPENCL_SAMPLES})
......@@ -36,6 +41,6 @@ if(${BOOST_BIOSEQ_BUILD_OPENCL_SAMPLES})
foreach(BENCHMARK ${BOOST_COMPUTE_BENCHMARKS})
set(PERF_TARGET perf_${BENCHMARK})
add_executable(${PERF_TARGET} perf_${BENCHMARK}.cpp)
target_link_libraries(${PERF_TARGET} ${OpenCL_LIBRARIES} ${Boost_LIBRARIES})
target_link_libraries(${PERF_TARGET} ${OpenCL_LIBRARIES} ${Boost_LIBRARIES} ${CONAN_LIBS})
endforeach()
endif()
\ No newline at end of file
//----------------------------------------------------------------------------//
// Copyright (c) 2018 Armin Sobhani <arminms@gmail.com>
//
// Distributed under the Boost Software License Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
//----------------------------------------------------------------------------//
#include <algorithm>
#include <numeric>
#include <vector>
#include <random>
// #include <boost/range/algorithm/copy.hpp>
// #include <boost/range/algorithm_ext/push_back.hpp>
// #include <boost/range/adaptor/transformed.hpp>
// #include <boost/range/adaptor/reversed.hpp>
#include <boost/bioseq/type_traits.hpp>
#include <boost/bioseq/sequence.hpp>
#include <benchmark/benchmark.h>
// #include "perf.hpp"
// #include "rss.hpp"
namespace bsq = boost::bioseq;
typedef bsq::sequence_host<char, std::allocator<char>, std::vector> seq;
char rand_seq()
{
char acgt[] = "ACGT";
std::random_device rd;
std::uniform_int_distribution<int> dist(0, 3);
return acgt[dist(rd)];
}
template <typename T>
void COPY_Constructor(benchmark::State& state)
{
T src(state.range(0));
std::generate(src.begin(), src.end(), rand);
// T src;
// src.reserve(state.range(0));
// std::generate_n(
// std::back_inserter(src)
// , state.range(0)
// , rand_seq);
for (auto _ : state)
{
T copied(src);
benchmark::DoNotOptimize(copied);
}
}
BENCHMARK_TEMPLATE(COPY_Constructor, std::vector<char>)
-> RangeMultiplier(10)
-> Range(10000, 1000000);
// -> Unit(benchmark::kMicrosecond);
BENCHMARK_TEMPLATE(COPY_Constructor, seq)
-> RangeMultiplier(10)
-> Range(10000, 1000000);
template <typename T>
void MOVE_Constructor(benchmark::State& state)
{
T src(state.range(0));
std::generate(src.begin(), src.end(), rand);
for (auto _ : state)
{
T moved(std::move(src));
benchmark::DoNotOptimize(moved);
}
}
BENCHMARK_TEMPLATE(MOVE_Constructor, std::vector<char>)
-> RangeMultiplier(10)
-> Range(10000, 1000000);
// -> Unit(benchmark::kMicrosecond);
BENCHMARK_TEMPLATE(MOVE_Constructor, seq)
-> RangeMultiplier(10)
-> Range(10000, 1000000);
template <typename T>
void Copy_Assignment_Op(benchmark::State& state)
{
T src(state.range(0));
std::generate(src.begin(), src.end(), rand);
for (auto _ : state)
{
T copied = src;
benchmark::DoNotOptimize(copied);
}
}
BENCHMARK_TEMPLATE(Copy_Assignment_Op, std::vector<char>)
-> RangeMultiplier(10)
-> Range(10000, 1000000);
// -> Unit(benchmark::kMicrosecond);
BENCHMARK_TEMPLATE(Copy_Assignment_Op, seq)
-> RangeMultiplier(10)
-> Range(10000, 1000000);
template <typename T>
void Move_Assignment_Op(benchmark::State& state)
{
T src(state.range(0));
std::generate(src.begin(), src.end(), rand);
for (auto _ : state)
{
T moved = std::move(src);
benchmark::DoNotOptimize(moved);
}
}
BENCHMARK_TEMPLATE(Move_Assignment_Op, std::vector<char>)
-> RangeMultiplier(10)
-> Range(10000, 1000000);
// -> Unit(benchmark::kMicrosecond);
BENCHMARK_TEMPLATE(Move_Assignment_Op, seq)
-> RangeMultiplier(10)
-> Range(10000, 1000000);
BENCHMARK_MAIN();
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment