On Friday 22 January 2016 20:46:54 Marc Mutz wrote:
> Which one is faster? On a dual-core, probably QVector. On a 64-core
> processor,  probably std::vector.

Running attached test program (4 cores + 2-fold HT), I get these numbers:

QVector;

1: 483
2: 492
4: 498
8: 503
16: 502
32: 513
64: 631
128: 615
256: 1070
512: 2202
1024: 3987
2048: 8531
4096: 16385

std::vector:

1: 132
2: 130
4: 125
8: 123
16: 140
32: 233
64: 370
128: 546
256: 994
512: 1931
1024: 3759
2048: 7383
4096: 14841

'Nuff said.

-- 
Marc Mutz <marc.m...@kdab.com> | Senior Software Engineer
KDAB (Deutschland) GmbH & Co.KG, a KDAB Group Company
Tel: +49-30-521325470
KDAB - The Qt Experts
#include <vector>
#include <QVector>
#include <thread>
#include <QThread>
#include <algorithm>
#include <chrono>
#include <iostream>

CONTAINER<int> make_vector(size_t size) {
    CONTAINER<int> result;
    result.resize(size);
    std::iota(result.begin(), result.end(), 1);
    return result;
}

int main() {

    const auto numThreads = QThread::idealThreadCount();

    const size_t jobs = 1024*1024;

    for (int size = 1; size <= 1024*4; size *= 2) {

        const auto v = make_vector(size);

        std::vector<std::thread> threads;
        threads.reserve(numThreads);

        auto start = std::chrono::high_resolution_clock::now();
    
        for (auto i = numThreads; i > 0; --i) {
            threads.emplace_back([&v,jobs, size]() {
                    volatile int result = 0;
                    for (auto i = jobs; i > 0; --i) {
                        const auto v2 = v;
                        for (auto e : v2)
                            result += e;
                    }
                });
        }

        for (auto &thread : threads)
            thread.join();

        auto end = std::chrono::high_resolution_clock::now();

        std::cout << size << ": " << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() << std::endl;
    }
}
_______________________________________________
Development mailing list
Development@qt-project.org
http://lists.qt-project.org/mailman/listinfo/development

Reply via email to