Commit d465af46 authored by Armin Sobhani's avatar Armin Sobhani
Browse files

add some benchmarking to perf folder

parent 7f6c7165
......@@ -69,10 +69,10 @@ if(${BOOST_BIOSEQ_BUILD_TESTS})
add_subdirectory(test)
endif()
# option(BOOST_BIOSEQ_BUILD_BENCHMARKS "Build the Boost.Bioseq benchmarks" OFF)
# if(${BOOST_BIOSEQ_BUILD_BENCHMARKS})
# add_subdirectory(perf)
# endif()
option(BOOST_BIOSEQ_BUILD_BENCHMARKS "Build the Boost.Bioseq benchmarks" ON)
if(${BOOST_BIOSEQ_BUILD_BENCHMARKS})
add_subdirectory(perf)
endif()
# option(BOOST_BIOSEQ_BUILD_EXAMPLES "Build the Boost.Bioseq examples" OFF)
# if(${BOOST_BIOSEQ_BUILD_EXAMPLES})
......
# ----------------------------------------------------------------------------
# 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_directories(../include)
set(BOOST_COMPONENTS system timer chrono program_options)
if(BOOST_COMPONENTS)
list(REMOVE_DUPLICATES BOOST_COMPONENTS)
endif()
find_package(Boost 1.53 REQUIRED COMPONENTS ${BOOST_COMPONENTS})
set(BENCHMARKS
stl_random_sequence
stl_reverse_complement
)
foreach(BENCHMARK ${BENCHMARKS})
set(PERF_TARGET perf_${BENCHMARK})
add_executable(${PERF_TARGET} perf_${BENCHMARK}.cpp)
target_link_libraries(${PERF_TARGET} ${OpenCL_LIBRARIES} ${Boost_LIBRARIES})
endforeach()
\ No newline at end of file
//---------------------------------------------------------------------------//
// Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@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
//
// See http://boostorg.github.com/compute for more information.
//---------------------------------------------------------------------------//
#ifndef PERF_HPP
#define PERF_HPP
// this header contains general purpose functions and variables used by
// the boost.compute performance benchmarks.
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <boost/lexical_cast.hpp>
#include <boost/timer/timer.hpp>
static size_t PERF_N = 1024;
static size_t PERF_TRIALS = 3;
// parses command line arguments and sets the corresponding perf variables
inline void perf_parse_args(int argc, char *argv[])
{
if(argc >= 2){
PERF_N = boost::lexical_cast<size_t>(argv[1]);
}
if(argc >= 3){
PERF_TRIALS = boost::lexical_cast<size_t>(argv[2]);
}
}
// generates a vector of random numbers
template<class T>
std::vector<T> generate_random_vector(const size_t size)
{
std::vector<T> vector(size);
std::generate(vector.begin(), vector.end(), rand);
return vector;
}
// a simple timer wrapper which records multiple time entries
class perf_timer
{
public:
typedef boost::timer::nanosecond_type nanosecond_type;
perf_timer()
{
timer.stop();
}
void start()
{
timer.start();
}
void stop()
{
timer.stop();
times.push_back(timer.elapsed().wall);
}
size_t trials() const
{
return times.size();
}
void clear()
{
times.clear();
}
nanosecond_type last_time() const
{
return times.back();
}
nanosecond_type min_time() const
{
return *std::min_element(times.begin(), times.end());
}
nanosecond_type max_time() const
{
return *std::max_element(times.begin(), times.end());
}
boost::timer::cpu_timer timer;
std::vector<boost::timer::nanosecond_type> times;
};
// returns the rate (in MB/s) for processing 'count' items of type 'T'
// in 'time' nanoseconds
template<class T>
double perf_rate(const size_t count, perf_timer::nanosecond_type time)
{
const size_t byte_count = count * sizeof(T);
return (double(byte_count) / 1024 / 1024) / (time / 1e9);
}
#endif // PERF_HPP
\ 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 <iostream>
#include <numeric>
#include <vector>
#include <random>
#include <boost/bioseq/type_traits.hpp>
#include <boost/bioseq/sequence.hpp>
#include "perf.hpp"
namespace bsq = boost::bioseq;
typedef bsq::sequence_host<char, std::allocator, std::vector> seq;
int main(int argc, char *argv[])
{
perf_parse_args(argc, argv);
std::cout << "size: " << PERF_N << std::endl;
char acgt[] = "ACGT";
std::random_device rd;
std::uniform_int_distribution<int> dist(0, 3);
perf_timer t;
for (size_t trial = 0; trial < PERF_TRIALS; ++trial)
{
seq rs;
rs.reserve(PERF_N);
t.start();
std::generate_n(
std::back_inserter(rs)
, PERF_N
, [&] () { return acgt[dist(rd)]; } );
t.stop();
}
std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl;
return 0;
}
\ 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 <iostream>
#include <numeric>
#include <vector>
#include <random>
#include <boost/range/algorithm/copy.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 "perf.hpp"
namespace bsq = boost::bioseq;
typedef bsq::sequence_host<char, std::allocator, std::vector> seq;
int main(int argc, char *argv[])
{
perf_parse_args(argc, argv);
std::cout << "size: " << PERF_N << std::endl;
char acgt[] = "ACGT";
std::random_device rd;
std::uniform_int_distribution<int> dist(0, 3);
seq rs;
rs.reserve(PERF_N);
// create vector of random sequence
std::generate_n(
std::back_inserter(rs)
, PERF_N
, [&] () { return acgt[dist(rd)]; } );
perf_timer t;
for (size_t trial = 0; trial < PERF_TRIALS; ++trial)
{
seq rc;
rc.reserve(PERF_N);
t.start();
boost::copy(
rs | boost::adaptors::transformed(
[] (char b) { if ('A' == b) return 'T';
else if ('T' == b) return 'A';
else if ('C' == b) return 'G';
else if ('G' == b) return 'C';
else return b ; } )
| boost::adaptors::reversed
, std::back_inserter(rc));
t.stop();
}
std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl;
return 0;
}
\ No newline at end of file
......@@ -24,21 +24,21 @@
#include <boost/bioseq/type_traits.hpp>
#include <boost/bioseq/sequence.hpp>
namespace bioseq = boost::bioseq;
namespace bsq = boost::bioseq;
// using boost::test_tools::output_test_stream;
// using boost::unit_test::runtime_config;
template<class CharT, class Allocator> using bs_string
= std::basic_string<CharT, std::char_traits<CharT>, Allocator>;
typedef bioseq::sequence_host<char, std::allocator, bs_string> str_seq;
typedef bioseq::sequence_host<char, std::allocator, std::vector> vec_seq;
typedef bioseq::sequence_host<wchar_t, std::allocator, bs_string> str_wseq;
typedef bioseq::sequence_host<wchar_t, std::allocator, std::vector> vec_wseq;
typedef bioseq::sequence_host<char16_t, std::allocator, bs_string> str_16seq;
typedef bioseq::sequence_host<char16_t, std::allocator, std::vector> vec_16seq;
typedef bioseq::sequence_host<char32_t, std::allocator, bs_string> str_32seq;
typedef bioseq::sequence_host<char32_t, std::allocator, std::vector> vec_32seq;
typedef bsq::sequence_host<char, std::allocator, bs_string> str_seq;
typedef bsq::sequence_host<char, std::allocator, std::vector> vec_seq;
typedef bsq::sequence_host<wchar_t, std::allocator, bs_string> str_wseq;
typedef bsq::sequence_host<wchar_t, std::allocator, std::vector> vec_wseq;
typedef bsq::sequence_host<char16_t, std::allocator, bs_string> str_16seq;
typedef bsq::sequence_host<char16_t, std::allocator, std::vector> vec_16seq;
typedef bsq::sequence_host<char32_t, std::allocator, bs_string> str_32seq;
typedef bsq::sequence_host<char32_t, std::allocator, std::vector> vec_32seq;
typedef boost::mpl::list<vec_seq, str_seq> seq_types;
typedef boost::mpl::list<vec_wseq, str_wseq> wseq_types;
......
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