-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
<random>
: normal_distribution
is slower than Boost
#1003
Comments
This comment was marked as resolved.
This comment was marked as resolved.
I overhauled the benchmark (dropping unnecessary code and especially the non-deterministic seeding) and got fresh numbers now that we've merged #4740. Click to expand new benchmark:diff --git a/benchmarks/CMakeLists.txt b/benchmarks/CMakeLists.txt
index 31572a96..c082ae50 100644
--- a/benchmarks/CMakeLists.txt
+++ b/benchmarks/CMakeLists.txt
@@ -114,6 +114,7 @@ add_benchmark(iota src/iota.cpp)
add_benchmark(locale_classic src/locale_classic.cpp)
add_benchmark(minmax_element src/minmax_element.cpp)
add_benchmark(mismatch src/mismatch.cpp)
+add_benchmark(normal_distribution src/normal_distribution.cpp)
add_benchmark(path_lexically_normal src/path_lexically_normal.cpp)
add_benchmark(priority_queue_push_range src/priority_queue_push_range.cpp)
add_benchmark(random_integer_generation src/random_integer_generation.cpp)
#include <benchmark/benchmark.h>
#include <random>
#pragma warning(push)
#pragma warning(disable : 4244) // conversion from 'meow' to 'woof', possible loss of data
#include <boost/random/mersenne_twister.hpp>
#include <boost/random/normal_distribution.hpp>
#include <boost/random/uniform_real_distribution.hpp>
#pragma warning(pop)
template <class RandomGenerator>
void BM_Generator(benchmark::State& state) {
RandomGenerator gen;
gen.discard(1'000'000);
while (state.KeepRunning()) {
benchmark::DoNotOptimize(gen());
}
}
template <class RandomGenerator, class Distribution>
void BM_Distribution(benchmark::State& state) {
RandomGenerator gen;
gen.discard(1'000'000);
Distribution dist(0.0, 1.0);
while (state.KeepRunning()) {
benchmark::DoNotOptimize(dist(gen));
}
}
namespace b_r = boost::random;
BENCHMARK(BM_Generator<std::mt19937_64>);
BENCHMARK(BM_Generator<b_r::mt19937_64>);
BENCHMARK(BM_Distribution<std::mt19937_64, std::normal_distribution<double>>);
BENCHMARK(BM_Distribution<std::mt19937_64, b_r::normal_distribution<double>>);
BENCHMARK(BM_Distribution<std::mt19937_64, std::uniform_real_distribution<double>>);
BENCHMARK(BM_Distribution<std::mt19937_64, b_r::uniform_real_distribution<double>>);
BENCHMARK(BM_Distribution<b_r::mt19937_64, std::normal_distribution<double>>);
BENCHMARK(BM_Distribution<b_r::mt19937_64, b_r::normal_distribution<double>>);
BENCHMARK(BM_Distribution<b_r::mt19937_64, std::uniform_real_distribution<double>>);
BENCHMARK(BM_Distribution<b_r::mt19937_64, b_r::uniform_real_distribution<double>>);
BENCHMARK_MAIN(); Click to expand build/run incantations:
I used VS 2022 17.12 Preview 2 on my 5950X. Table:
With And now our I conclude that our underlying algorithm for |
<random>
: normal_distribution
is slower than Boost
Describe the bug
A benchmark by Alexander Neumann (original issue reporter) showed that
std::normal_distribution
withstd::mt19937_64
was 4 times slower thanboost::normal_distribution
withstd::mt19937_64
.Additional context
Part of the performance deficiency is due to #1000.
Also tracked by DevCom-86909 and Microsoft-internal VSO-486661 / AB#486661.
The text was updated successfully, but these errors were encountered: