Why is valarray so slow?

后端 未结 7 2001
情书的邮戳
情书的邮戳 2020-12-23 15:18

I am trying to use valarray since it is much like MATLAB while operating vector and matrices. I first did some performance check and found that valarray cannot achieve the p

7条回答
  •  心在旅途
    2020-12-23 15:39

    I just tried it on a Linux x86-64 system (Sandy Bridge CPU):

    gcc 4.5.0:

    double operator* 9.64185 ms
    valarray operator* 9.36987 ms
    valarray[i] operator* 9.35815 ms
    

    Intel ICC 12.0.2:

    double operator* 7.76757 ms
    valarray operator* 9.60208 ms
    valarray[i] operator* 7.51409 ms
    

    In both cases I just used -O3 and no other optimisation-related flags.

    It looks like the MS C++ compiler and/or valarray implementation suck.


    Here's the OP's code modified for Linux:

    #include 
    #include 
    #include 
    #include 
    
    using namespace std ;
    
    double gettime_hp();
    
    int main()
    {
        enum { N = 5*1024*1024 };
        valarray a(N), b(N), c(N) ;
        int i,j;
        for(  j=0 ; j<8 ; ++j )
        {
            for(  i=0 ; i

提交回复
热议问题