<html>
<head>
<base href="http://llvm.org/bugs/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW --- - Odd performance drop with mt19937 and uniform_real_distribution"
href="http://llvm.org/bugs/show_bug.cgi?id=19542">19542</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Odd performance drop with mt19937 and uniform_real_distribution
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>3.4
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>C++11
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>swerhausen@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>dgregor@apple.com, llvmbugs@cs.uiuc.edu
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>When using mt19937 or mt19937_64 in combination with a
uniform_real_distribution, the performance is about an order of magnitude worse
than gcc's. But it only happens with that particular combination. Those
generators are fine with uniform_int_distribution, and another generator like
default_random_engine works fine with uniform_real_distribution. A program to
reproduce this and my results:
#include <iostream>
#include <vector>
#include <chrono>
#include <random>
template< typename T_rng, typename T_dist>
double timer(T_rng& rng, T_dist& dist, int n){
std::vector< typename T_dist::result_type > vec(n, 0);
auto t1 = std::chrono::high_resolution_clock::now();
for (int i = 0; i < n; ++i)
vec[i] = dist(rng);
auto t2 = std::chrono::high_resolution_clock::now();
auto runtime =
std::chrono::duration_cast<std::chrono::microseconds>(t2-t1).count()/1000.0;
return runtime;
}
int main(){
const int n = 10000000;
std::default_random_engine rng_default(1);
std::mt19937 rng_mt (1);
std::mt19937_64 rng_mt_64 (1);
std::uniform_int_distribution<int> dist_int(0,1000);
std::uniform_real_distribution<float> dist_float(0.0, 1.0);
std::cout << "int_default: " << timer(rng_default, dist_int, n) <<
std::endl;
std::cout << "int_mt: " << timer(rng_mt_64, dist_int, n) << std::endl;
std::cout << "int_mt_64: " << timer(rng_mt_64, dist_int, n) << std::endl;
std::cout << "float_default: " << timer(rng_default, dist_float, n) <<
std::endl;
std::cout << "float_mt: " << timer(rng_mt, dist_float, n) << std::endl;
std::cout << "float_mt_64: " << timer(rng_mt_64, dist_float, n) <<
std::endl;
}
result for my linux 64bit:
// g++ 4.8.1
int_default: 184.687
int_mt: 176.092
int_mt_64: 176.076
float_default: 45.478
float_mt: 58.018
float_mt_64: 90.073
// clang 3.4
int_default: 207.594
int_mt: 195.68
int_mt_64: 195.702
float_default: 54.535
float_mt: 747.402 <----- slow
float_mt_64: 781.237 <-- slow</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>