http://llvm.org/bugs/show_bug.cgi?id=19542

            Bug ID: 19542
           Summary: Odd performance drop with mt19937 and
                    uniform_real_distribution
           Product: clang
           Version: 3.4
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++11
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected]
    Classification: Unclassified

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

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to