相关疑难解决方法(0)

qsort vs std :: sort的表现?

根据Scott Meyers的说法,在他的Effective STL书中 - 第46项.他声称这std::sortstd::qsort内联的事实要快670%.我测试了自己,我看到qsort更快:(!有谁可以帮我解释这个奇怪的行为?

#include <iostream>
#include <vector>
#include <algorithm>

#include <cstdlib>
#include <ctime>
#include <cstdio>

const size_t LARGE_SIZE = 100000;

struct rnd {
    int operator()() {
        return rand() % LARGE_SIZE;
    }
};

int comp( const void* a, const void* b ) {
    return ( *( int* )a - *( int* )b );
}

int main() {
    int ary[LARGE_SIZE];
    int ary_copy[LARGE_SIZE];
    // generate random data
    std::generate( ary, ary + LARGE_SIZE, rnd() );
    std::copy( ary, ary …
Run Code Online (Sandbox Code Playgroud)

c++ sorting performance stl

70
推荐指数
6
解决办法
6万
查看次数

标签 统计

c++ ×1

performance ×1

sorting ×1

stl ×1