Skip to content

Commit

Permalink
Merge 329f1be into 8c413d8
Browse files Browse the repository at this point in the history
  • Loading branch information
izvolov committed Jun 27, 2020
2 parents 8c413d8 + 329f1be commit a22de27
Show file tree
Hide file tree
Showing 23 changed files with 180 additions and 128 deletions.
11 changes: 3 additions & 8 deletions benchmark/CMakeLists.txt
@@ -1,12 +1,7 @@
find_package(Boost 1.62.0 COMPONENTS program_options REQUIRED)

add_library(benchIO INTERFACE)
target_include_directories(benchIO INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
target_include_directories(benchIO INTERFACE include)

add_executable(rangegen range_generator.cpp)
target_link_libraries(rangegen PRIVATE Burst::burst benchIO Boost::program_options)

add_subdirectory(algorithm)
add_subdirectory(container)
add_subdirectory(integer)
add_subdirectory(iterator)
add_subdirectory(burst)
add_subdirectory(src)
4 changes: 4 additions & 0 deletions benchmark/burst/CMakeLists.txt
@@ -0,0 +1,4 @@
add_subdirectory(algorithm)
add_subdirectory(container)
add_subdirectory(integer)
add_subdirectory(iterator)
File renamed without changes.
@@ -1,5 +1,6 @@
#include <utility/io/read.hpp>

#include <burst/algorithm/galloping_lower_bound.hpp>
#include <io.hpp>

#include <boost/program_options.hpp>

Expand Down Expand Up @@ -54,7 +55,7 @@ int main (int argc, const char * argv[])
else
{
std::vector<std::int64_t> numbers;
read(std::cin, numbers);
utility::read(std::cin, numbers);

std::size_t attempts = vm["attempts"].as<std::size_t>();
test(numbers, attempts, [] (auto f, auto l, const auto & v) {return burst::galloping_lower_bound(f, l, v);}, "gallop");
Expand Down
Expand Up @@ -11,7 +11,7 @@ def measure (lengths, max_attempts, integer_type, prepare):
measurements = {}

command_template =\
("@CMAKE_BINARY_DIR@/benchmark/rangegen "
("@CMAKE_BINARY_DIR@/benchmark/src/rangegen "
"--count=1 "
"--length={} | "
"@CMAKE_BINARY_DIR@/benchmark/algorithm/radix "
Expand Down
@@ -1,6 +1,7 @@
#include <utility/io/read.hpp>

#include <burst/algorithm/radix_sort.hpp>
#include <burst/functional/identity.hpp>
#include <io.hpp>

#include <boost/program_options.hpp>
#include <boost/sort/spreadsort/integer_sort.hpp>
Expand Down Expand Up @@ -43,7 +44,7 @@ template <typename Integer, typename UnaryFunction>
void test_all (std::size_t attempts, UnaryFunction prepare)
{
std::vector<Integer> numbers;
read(std::cin, numbers);
utility::read(std::cin, numbers);

std::vector<Integer> buffer(numbers.size());

Expand Down
File renamed without changes.
File renamed without changes.
@@ -1,5 +1,6 @@
#include <utility/io/read.hpp>

#include <burst/container/k_ary_search_set.hpp>
#include <io.hpp>

#include <boost/container/flat_set.hpp>
#include <boost/program_options.hpp>
Expand Down Expand Up @@ -80,7 +81,7 @@ void test (const Container & arities, std::size_t attempts)
{
using integer_type = std::int64_t;
std::vector<integer_type> numbers;
read(std::cin, numbers);
utility::read(std::cin, numbers);
std::sort(numbers.begin(), numbers.end());
numbers.erase(std::unique(numbers.begin(), numbers.end()), numbers.end());

Expand Down
File renamed without changes.
@@ -1,5 +1,6 @@
#include <utility/io/read.hpp>

#include <burst/integer/divceil.hpp>
#include <io.hpp>

#include <boost/program_options.hpp>
#include <boost/tuple/tuple.hpp>
Expand Down Expand Up @@ -44,7 +45,7 @@ template <typename Integer1, typename Integer2>
void test_all (std::int64_t divisor, std::size_t attempt_count)
{
std::vector<Integer1> values;
read(std::cin, values);
utility::read(std::cin, values);

test_divceil(values, static_cast<Integer2>(divisor), attempt_count);
}
Expand Down
File renamed without changes.
@@ -1,5 +1,6 @@
#include <utility/io/read_many.hpp>

#include <burst/range/intersect.hpp>
#include <io.hpp>

#include <boost/range/algorithm/for_each.hpp>
#include <boost/range/iterator_range.hpp>
Expand Down Expand Up @@ -53,7 +54,7 @@ void test_std_intersect (const Container & values)
int main ()
{
std::vector<std::vector<std::int64_t>> values;
read_many(std::cin, values);
utility::read_many(std::cin, values);

test_std_intersect(values);
test_on_the_fly_intersect(values);
Expand Down
@@ -1,6 +1,7 @@
#include <utility/io/read_many.hpp>

#include <burst/iterator/merge_iterator.hpp>
#include <burst/range/merge.hpp>
#include <io.hpp>

#include <boost/assert.hpp>
#include <boost/range/algorithm/for_each.hpp>
Expand Down Expand Up @@ -85,7 +86,7 @@ void test_std_merge (const Container & values)
int main ()
{
std::vector<std::vector<std::int64_t>> values;
read_many(std::cin, values);
utility::read_many(std::cin, values);

test_merge_by_sorting(values);
test_std_merge(values);
Expand Down
@@ -1,5 +1,6 @@
#include <utility/io/read.hpp>

#include <burst/iterator/subset_iterator.hpp>
#include <io.hpp>

#include <iostream>
#include <vector>
Expand Down Expand Up @@ -28,7 +29,7 @@ void test (const Container & numbers)
int main ()
{
std::vector<std::int64_t> numbers;
read(std::cin, numbers);
utility::read(std::cin, numbers);

test(numbers);
}
62 changes: 62 additions & 0 deletions benchmark/include/utility/io/generate.hpp
@@ -0,0 +1,62 @@
#ifndef BURST_BENCHMARK_UTILITY_IO_GENERATE_HPP
#define BURST_BENCHMARK_UTILITY_IO_GENERATE_HPP

#include <utility/io/write.hpp>

#include <algorithm>
#include <chrono>
#include <cstddef>
#include <cstdint>
#include <functional>
#include <ostream>
#include <random>
#include <vector>

namespace utility
{
std::ostream &
generate
(
std::ostream & stream,
std::size_t range_count,
std::size_t range_length,
std::int64_t min,
std::int64_t max,
bool seed,
bool sort,
bool descending
)
{
auto seed_value = seed
? static_cast<std::default_random_engine::result_type>
(
std::chrono::system_clock::now().time_since_epoch().count()
)
: 0;
std::default_random_engine engine(seed_value);
std::uniform_int_distribution<std::int64_t> uniform(min, max);

std::vector<std::int64_t> range(range_length);
for (std::size_t i = 0; i < range_count; ++i)
{
std::generate(range.begin(), range.end(), [&] () { return uniform(engine); });
if (sort)
{
if (descending)
{
std::sort(range.begin(), range.end(), std::greater<>{});
}
else
{
std::sort(range.begin(), range.end());
}
}

write(stream, range);
}

return stream;
}
} // namespace utility

#endif // BURST_BENCHMARK_UTILITY_IO_GENERATE_HPP
32 changes: 32 additions & 0 deletions benchmark/include/utility/io/read.hpp
@@ -0,0 +1,32 @@
#ifndef BURST_BENCHMARK_UTILITY_IO_READ_HPP
#define BURST_BENCHMARK_UTILITY_IO_READ_HPP

#include <burst/functional/trivial_read.hpp>

#include <cstddef>
#include <cstdint>
#include <istream>

namespace utility
{
template <typename Container>
std::istream & read (std::istream & stream, Container & values)
{
auto size = std::size_t{};
if (burst::trivial_read(stream, size))
{
values.resize(size);

for (auto & value: values)
{
auto n = std::int64_t{};
burst::trivial_read(stream, n);
value = static_cast<typename Container::value_type>(n);
}
}

return stream;
}
} // namespace utility

#endif // BURST_BENCHMARK_UTILITY_IO_READ_HPP
23 changes: 23 additions & 0 deletions benchmark/include/utility/io/read_many.hpp
@@ -0,0 +1,23 @@
#ifndef BURST_BENCHMARK_UTILITY_IO_READ_MANY_HPP
#define BURST_BENCHMARK_UTILITY_IO_READ_MANY_HPP

#include <utility/io/read.hpp>

#include <istream>

namespace utility
{
template <typename Container>
std::istream & read_many (std::istream & stream, Container & containers)
{
auto container = typename Container::value_type{};
while (read(stream, container))
{
containers.push_back(container);
}

return stream;
}
} // namespace utility

#endif // BURST_BENCHMARK_UTILITY_IO_READ_MANY_HPP
28 changes: 28 additions & 0 deletions benchmark/include/utility/io/write.hpp
@@ -0,0 +1,28 @@
#ifndef BURST_BENCHMARK_UTILITY_IO_WRITE_HPP
#define BURST_BENCHMARK_UTILITY_IO_WRITE_HPP

#include <burst/functional/trivial_write.hpp>
#include <burst/iterator/binary_ostream_iterator.hpp>

#include <boost/range/algorithm/transform.hpp>

#include <cstddef>
#include <cstdint>
#include <ostream>

namespace utility
{
template <typename Container>
std::ostream & write (std::ostream & stream, const Container & values)
{
burst::trivial_write(stream, static_cast<std::size_t>(values.size()));
boost::transform(values, burst::make_binary_ostream_iterator(stream),
[] (std::int64_t v) {return v;});
// Элементы контейнера должны уметь неявно (то есть без потерь) преобразовываться к
// std::int64_t, т.к. это "официальный" формат обмена числами между приложениями.

return stream;
}
} // namespace utility

#endif // BURST_BENCHMARK_UTILITY_IO_WRITE_HPP
57 changes: 0 additions & 57 deletions benchmark/io.hpp

This file was deleted.

2 changes: 2 additions & 0 deletions benchmark/src/CMakeLists.txt
@@ -0,0 +1,2 @@
add_executable(rangegen range_generator.cpp)
target_link_libraries(rangegen PRIVATE Burst::burst benchIO Boost::program_options)

0 comments on commit a22de27

Please sign in to comment.