Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/windirstat/llfio.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiall Douglas (s [underscore] sourceforge {at} nedprod [dot] com) <spamtrap@nedprod.com>2021-02-23 15:58:10 +0300
committerNiall Douglas (s [underscore] sourceforge {at} nedprod [dot] com) <spamtrap@nedprod.com>2021-03-16 13:21:44 +0300
commitd18a3b15a7f2201fc6e175f5a23d2426c4cea5c7 (patch)
treeeb737d9b3608ead46775c8da2cb8ad58e14b6fd3 /programs
parentbb4719390b20944395e6a62522d395f0228fa3da (diff)
Begin dynamic_thread_pool_group benchmark program.
Diffstat (limited to 'programs')
-rw-r--r--programs/CMakeLists.txt7
-rw-r--r--programs/benchmark-async/main.cpp4
-rw-r--r--programs/benchmark-dynamic_thread_pool_group/main.cpp177
3 files changed, 183 insertions, 5 deletions
diff --git a/programs/CMakeLists.txt b/programs/CMakeLists.txt
index 07db5753..ad4bb919 100644
--- a/programs/CMakeLists.txt
+++ b/programs/CMakeLists.txt
@@ -11,8 +11,7 @@ find_quickcpplib_library(quickcpplib
)
find_quickcpplib_library(outcome
GIT_REPOSITORY "https://github.com/ned14/outcome.git"
-# GIT_TAG "develop"
- GIT_TAG "better_optimisation" ## future Outcome v2.2
+ GIT_TAG "master"
REQUIRED
IS_HEADER_ONLY
)
@@ -48,13 +47,15 @@ function(make_program program)
endfunction()
make_program(benchmark-async llfio::hl)
+make_program(benchmark-dynamic_thread_pool_group llfio::hl)
make_program(benchmark-iostreams llfio::hl)
make_program(benchmark-locking llfio::hl kerneltest::hl)
make_program(fs-probe llfio::hl)
make_program(illegal-codepoints llfio::hl)
make_program(key-value-store llfio::hl)
-target_include_directories(benchmark-async PRIVATE "benchmark-async/asio/asio/include")
+target_include_directories(benchmark-async PRIVATE "asio/asio/include")
+target_include_directories(benchmark-dynamic_thread_pool_group PRIVATE "asio/asio/include")
if(MSVC)
target_compile_options(illegal-codepoints PUBLIC /utf-8)
diff --git a/programs/benchmark-async/main.cpp b/programs/benchmark-async/main.cpp
index 1213dd4f..613f338d 100644
--- a/programs/benchmark-async/main.cpp
+++ b/programs/benchmark-async/main.cpp
@@ -377,13 +377,13 @@ completion i/o min 1300 max 1.40714e+06 mean 23037 stddev 15035.4
#include <typeinfo>
#include <vector>
-#if __has_include("asio/asio/include/asio.hpp")
+#if __has_include("../asio/asio/include/asio.hpp")
#define ENABLE_ASIO 1
#if defined(__clang__) && defined(_MSC_VER)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmicrosoft-include"
#endif
-#include "asio/asio/include/asio.hpp"
+#include "../asio/asio/include/asio.hpp"
#if defined(__clang__) && defined(_MSC_VER)
#pragma clang diagnostic pop
#endif
diff --git a/programs/benchmark-dynamic_thread_pool_group/main.cpp b/programs/benchmark-dynamic_thread_pool_group/main.cpp
new file mode 100644
index 00000000..d5a9cd31
--- /dev/null
+++ b/programs/benchmark-dynamic_thread_pool_group/main.cpp
@@ -0,0 +1,177 @@
+/* Test the performance of dynamic thread pool group
+(C) 2021 Niall Douglas <http://www.nedproductions.biz/> (6 commits)
+File Created: Feb 2021
+
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License in the accompanying file
+Licence.txt or at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+
+Distributed under the Boost Software License, Version 1.0.
+ (See accompanying file Licence.txt or copy at
+ http://www.boost.org/LICENSE_1_0.txt)
+*/
+
+//! Seconds to run the benchmark
+static constexpr unsigned BENCHMARK_DURATION = 3;
+//! Maximum work items to create
+static constexpr unsigned MAX_WORK_ITEMS = 1024;
+
+#include "../../include/llfio/llfio.hpp"
+
+#include "quickcpplib/algorithm/small_prng.hpp"
+
+#include <cfloat>
+#include <chrono>
+#include <cmath>
+#include <fstream>
+#include <iostream>
+#include <thread>
+#include <tuple>
+#include <vector>
+
+#if __has_include("../asio/asio/include/asio.hpp")
+#define ENABLE_ASIO 1
+#if defined(__clang__) && defined(_MSC_VER)
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wmicrosoft-include"
+#endif
+#include "../asio/asio/include/asio.hpp"
+#if defined(__clang__) && defined(_MSC_VER)
+#pragma clang diagnostic pop
+#endif
+#endif
+
+namespace llfio = LLFIO_V2_NAMESPACE;
+
+struct asio_runner
+{
+ std::atomic<bool> cancel{false};
+ asio::io_context ctx;
+
+ template <class F> struct C
+ {
+ asio_runner *parent;
+ F f;
+ C(asio_runner *_parent, F &&_f)
+ : parent(_parent)
+ , f(std::move(_f))
+ {
+ }
+ void operator()() const
+ {
+ f();
+ if(!parent->cancel.load(std::memory_order_relaxed))
+ {
+ parent->ctx.post(*this);
+ }
+ }
+ };
+ template <class F> void add_workitem(F &&f) { ctx.post(C(this, std::move(f))); }
+ void run(unsigned seconds)
+ {
+ std::vector<std::thread> threads;
+ for(size_t n = 0; n < std::thread::hardware_concurrency(); n++)
+ {
+ threads.emplace_back([&] { ctx.run(); });
+ }
+ std::this_thread::sleep_for(std::chrono::seconds(seconds));
+ cancel.store(true, std::memory_order_release);
+ for(auto &i : threads)
+ {
+ i.join();
+ }
+ }
+};
+
+template <class Runner> void benchmark(const char *name)
+{
+ std::cout << "Benchmarking " << name << " ..." << std::endl;
+ struct shared_t
+ {
+ std::atomic<unsigned> concurrency{0};
+ std::atomic<unsigned> max_concurrency{0};
+ };
+ struct worker
+ {
+ shared_t *shared;
+ char buffer[4096];
+ QUICKCPPLIB_NAMESPACE::algorithm::hash::sha256_hash::result_type hash;
+ uint64_t count{0};
+
+ void operator()()
+ {
+ auto concurrency = shared->concurrency.fetch_add(1, std::memory_order_relaxed) + 1;
+ if(concurrency > shared->max_concurrency.load(std::memory_order_relaxed))
+ {
+ shared->max_concurrency.store(concurrency, std::memory_order_relaxed);
+ }
+ hash = QUICKCPPLIB_NAMESPACE::algorithm::hash::sha256_hash::hash(buffer, sizeof(buffer));
+ count++;
+ shared->concurrency.fetch_sub(1, std::memory_order_relaxed);
+ }
+ explicit worker(shared_t *_shared)
+ : shared(_shared)
+ {
+ }
+ };
+ std::vector<worker> workers;
+ std::vector<std::tuple<size_t, double, unsigned>> results;
+ QUICKCPPLIB_NAMESPACE::algorithm::small_prng::small_prng rand;
+ for(size_t items = 1; items <= MAX_WORK_ITEMS; items <<= 1)
+ {
+ shared_t shared;
+ workers.clear();
+ for(size_t n = 0; n < items; n++)
+ {
+ workers.emplace_back(&shared);
+ for(size_t i = 0; i < sizeof(worker::buffer); i += 4)
+ {
+ auto *p = (uint32_t *) (workers.back().buffer + i);
+ *p = rand();
+ }
+ }
+ Runner runner;
+ for(auto &i : workers)
+ {
+ runner.add_workitem([&] { i(); });
+ }
+ auto begin = std::chrono::steady_clock::now();
+ runner.run(BENCHMARK_DURATION);
+ auto end = std::chrono::steady_clock::now();
+ uint64_t total = 0;
+ for(auto &i : workers)
+ {
+ total += i.count;
+ }
+ results.emplace_back(items, 1000000.0 * total / std::chrono::duration_cast<std::chrono::microseconds>(end - begin).count(), shared.max_concurrency);
+ std::cout << " For " << std::get<0>(results.back()) << " work items got " << std::get<1>(results.back()) << " SHA256 hashes/sec with "
+ << std::get<2>(results.back()) << " maximum concurrency." << std::endl;
+ }
+ std::ofstream out(std::string(name) + "_results.csv");
+ out << R"("Work items","SHA256 hashes/sec","Max concurrency")";
+ for(auto &i : results)
+ {
+ out << "\n" << std::get<0>(i) << "," << std::get<1>(i) << "," << std::get<2>(i);
+ }
+ out << std::endl;
+}
+
+int main(void)
+{
+#if ENABLE_ASIO
+ benchmark<asio_runner>("asio");
+#endif
+
+ return 0;
+} \ No newline at end of file