1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
|
// -----------------------------------------------------------------------------------------------------
// Copyright (c) 2006-2020, Knut Reinert & Freie Universität Berlin
// Copyright (c) 2016-2020, Knut Reinert & MPI für molekulare Genetik
// This file may be used, modified and/or redistributed under the terms of the 3-clause BSD-License
// shipped with this file and also available at: https://github.com/seqan/seqan3/blob/master/LICENSE.md
// -----------------------------------------------------------------------------------------------------
#include <benchmark/benchmark.h>
#include <fstream>
#include <iostream>
#include <iterator>
#include <seqan3/alphabet/aminoacid/all.hpp>
#include <seqan3/io/stream/iterator.hpp>
#include <seqan3/test/performance/sequence_generator.hpp>
#include <seqan3/test/seqan2.hpp>
#include <seqan3/test/tmp_filename.hpp>
#if SEQAN3_HAS_SEQAN2
#include <seqan/stream.h>
#endif
enum class tag
{
std_stream_it,
std_streambuf_it,
seqan3_streambuf_it,
seqan2_stream_it
};
template <tag id>
void read_all(benchmark::State & state)
{
/* prepare file for reading */
seqan3::test::tmp_filename filename{"foo"};
{
std::ofstream os{filename.get_path(), std::ios::binary};
std::vector<seqan3::aa27> cont_rando = seqan3::test::generate_sequence<seqan3::aa27>(10'000, 0, 0);
for (size_t i = 0; i < 100; ++i)
for (auto c : cont_rando)
os.put(seqan3::to_char(c));
}
/* start benchmark */
char c{}; // prevents optimisation
if constexpr (id == tag::std_stream_it)
{
for (auto _ : state)
{
std::ifstream s{filename.get_path(), std::ios::binary};
std::istream_iterator<char> it{s};
std::istream_iterator<char> e{};
for (; it != e; ++it)
c += *it;
}
}
else if constexpr (id == tag::std_streambuf_it)
{
for (auto _ : state)
{
std::ifstream s{filename.get_path(), std::ios::binary};
std::istreambuf_iterator<char> it{s};
std::istreambuf_iterator<char> e{};
for (; it != e; ++it)
c += *it;
}
}
else if constexpr (id == tag::seqan3_streambuf_it)
{
for (auto _ : state)
{
std::ifstream s{filename.get_path(), std::ios::binary};
seqan3::detail::fast_istreambuf_iterator<char> it{*s.rdbuf()};
std::default_sentinel_t e{};
for (; it != e; ++it)
c += *it;
}
}
#ifdef SEQAN3_HAS_SEQAN2
else if constexpr (id == tag::seqan2_stream_it)
{
for (auto _ : state)
{
std::ifstream s{filename.get_path(), std::ios::binary};
auto it = seqan::Iter<std::ifstream, seqan::StreamIterator<seqan::Input>>{s};
for (; !seqan::atEnd(it); ++it)
c += *it;
}
}
#endif
}
BENCHMARK_TEMPLATE(read_all, tag::std_stream_it);
BENCHMARK_TEMPLATE(read_all, tag::std_streambuf_it);
BENCHMARK_TEMPLATE(read_all, tag::seqan3_streambuf_it);
#ifdef SEQAN3_HAS_SEQAN2
BENCHMARK_TEMPLATE(read_all, tag::seqan2_stream_it);
#endif
BENCHMARK_MAIN();
|