This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

gcc-4.7 std::sort is much slower than gcc-4.4.6?


gcc-4.7 std::sort is much slower than gcc-4.4.6?

////////////////
#include <algorithm>
#include <vector>
#include <stdio.h>
#include <math.h>

int main(int argc, char* argv[])
{
???????? size_t size = 1000000;
???????? int loop = 200;

???????? if (argc >= 2)
???????? {
?????????????????? loop = strtoul(argv[1], NULL, 0);
???????? }
???????? if (argc >= 3)
???????? {
?????????????????? size = strtoul(argv[2], NULL, 0);
???????? }

???????? std::vector<int> seq, buf;
???????? seq.reserve(size);
???????? srand(0);
???????? for (int i = 0; i < size; i++) {
?????????????????? seq.push_back(rand());
???????? }
???????? for (int i = 0; i < loop; ++i) {
?????????????????? buf = seq;
?????????????????? std::sort(buf.begin(), buf.end());
???????? }
} ////////////////

[root@djt-17-109-v06 tmp]# g++47 -std=gnu++11 -g -O2 tsort.cpp -o a47 && g++ -std=gnu++0x -g -O2 tsort.cpp? -o a44
[root@djt-17-109-v06 tmp]# time ./a47 && time ./a47 && time ./a44 && time ./a44

real? 0m23.083s
user 0m23.067s
sys?? 0m0.012s

real? 0m23.166s
user 0m23.146s
sys?? 0m0.017s

real? 0m21.337s
user 0m21.320s
sys?? 0m0.012s

real? 0m21.361s
user 0m21.340s
sys?? 0m0.019s

It seems gcc-4.4.6 is about 10% faster than gcc-4.7 in general std::sort.

Regards
Kirby Zhou
+86 (10) 6272 8261


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]