11

std::sort(構造体の使用std::vector)とIntelippソートのパフォーマンスを比較しようとしています。

Intel Xeon プロセッサでこのテストを実行していますmodel name : Intel(R) Xeon(R) CPU X5670 @ 2.93GHz

長さ 20000 要素のベクトルをソートし、200 回ソートしています。ipp私は2つの異なるソートルーチンを試しました。ippsSortDescend_64f_IippsSortRadixDescend_64f_I。いずれの場合も、ipp並べ替えは少なくとも 5 ~ 10 倍遅くなりstd::sortました。ipp小さい配列ではソートが遅くなる可能性があると予想していましたが、それ以外の場合は一般的に よりも高速になるはずですstd::sort。ここで何か不足していますか?私は何を間違っていますか?

std::sort私のすべてのテストケースで一貫して高速です。

これが私のプログラムです

#include <array>
#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <time.h>
#include <sys/time.h>
#include <sys/timeb.h>

#include <vector>
#include <chrono>

#include "ipp.h"

using namespace std;

const int SIZE = 2000000;
const int ITERS = 200;

//Chrono typedefs
typedef std::chrono::high_resolution_clock Clock;
typedef std::chrono::microseconds microseconds;

//////////////////////////////////// std ///////////////////////////////////

typedef vector<double> myList;

void initialize(myList & l, Ipp64f* ptr)
{
    double randomNum;
    for (int i = 0; i < SIZE; i++)
    {
        randomNum =  1.0 * rand() / (RAND_MAX / 2) - 1;
        l.push_back(randomNum);
        ptr[i] = randomNum;
    }
}


void test_sort()
{
        array<myList, ITERS> list;
        array<Ipp64f*, ITERS> ippList;

        // allocate
        for(int i=0; i<ITERS;i++)
        {
                list[i].reserve(SIZE);
                ippList[i] = ippsMalloc_64f(SIZE);
        }

        // initialize
        for(int i=0;i<ITERS;i++)
        {
                initialize(list[i], ippList[i]);
        }

        cout << "\n\nTest Case 1: std::sort\n";
        cout << "========================\n";

        // sort vector
        Clock::time_point t0 = Clock::now();
        for(int i=0; i<ITERS;i++)
        {
            std::sort(list[i].begin(), list[i].end());
        }
        Clock::time_point t1 = Clock::now();
        microseconds ms = std::chrono::duration_cast<microseconds>(t1 - t0);
        std::cout << ms.count() << " micros" << std::endl;

        ////////////////////////////////// IPP ////////////////////////////////////////

        cout << "\n\nTest Case 2: ipp::sort\n";
        cout << "========================\n";

        // sort ipp 
        Clock::time_point t2 = Clock::now();
        for(int i=0; i<ITERS;i++)
        {
                ippsSortAscend_64f_I(ippList[i], SIZE);
        }
        Clock::time_point t3 = Clock::now();
        microseconds ms1 = std::chrono::duration_cast<microseconds>(t3 - t2);
        std::cout << ms1.count() << " micros" << std::endl;

        for(int i=0; i<ITERS;i++)
        {
          ippsFree( ippList[i] );
        }
}


///////////////////////////////////////////////////////////////////////////////////////

int main()
{
    srand (time(NULL));

    cout << "Test for sorting an array of structures.\n" << endl;
    cout << "Test case: \nSort an array of structs ("<<ITERS<<" iterations) with double of length "<<SIZE<<". \n";
        IppStatus status=ippInit();
        test_sort();
    return 0;
}

/////////////////////////////////////////////////////////////////////////////

コンパイルコマンドは次のとおりです。

/share/intel/bin/icc -O2 -I$(IPPROOT)/include  sorting.cpp -lrt -L$(IPPROOT)/lib/intel64 -lippi -lipps -lippvm -lippcore -std=c++0x    

プログラム出力:

Test for sorting an array of structures.

Test case:
Sort an array of structs (200 iterations) with double of length 2000000.


Test Case 1: std::sort
========================
38117024 micros


Test Case 2: ipp::sort
========================
48917686 micros
4

3 に答える 3

5

あなたのコードを自分のコンピューター (Core i7 860) で実行しました。

 std::sort 32,763,268 (~33s)

 ippsSortAscend_64f_I 34,217,517 (~34s)

 ippsSortRadixAscend_64f_I 15,319,053 (~15s)

これらは期待される結果です。std::sort はインラインで高度に最適化されていますが、ippsSort_* には関数呼び出しのオーバーヘッドがあり、すべての ipp 関数によって多くの内部チェックが実行されます。これは、ippsSortAscend 関数の速度低下を説明するはずです。基数ソートは、比較ベースのソートではないため、予想の 2 倍高速です。

于 2015-09-14T07:29:30.460 に答える
1

より正確な結果を得るには、

  • 乱数のまったく同じ分布の並べ替えを比較します。
  • タイミングからランダム化を削除します。
  • ippsSort*32f 関数を使用して、IPP ケースで「float」(「double」ではない) をソートします。
于 2015-08-26T12:36:59.257 に答える