I used to think that multithreading is most efficient when we are performing blocking operations and during that time we can proceed with other instructions on another threads.

Recently I have executed simple test. I have created a data vector and splitted equally the rows between threads and compare execution time with one thread worker. The multithreading was the winner.

Heres my code:

```
#include <iostream>
#include <thread>
#include <vector>
#include <mutex>
#include <numeric>
#include <chrono>

double g_sum = 0;
std::mutex g_mutex;

void worker(const std::vector<double>& vec)
{
    const auto vectorSum = std::accumulate(vec.begin(), vec.end(), 0.0);
    std::lock_guard<std::mutex> lg(g_mutex);
    std::cout << "Thread-Worker adding " << vectorSum << " to final sum ("<< g_sum <<")\n";
    g_sum += vectorSum;
}

int main()
{
    const int ROW_SIZE = 10000000;
    const int threadsSize = std::thread::hardware_concurrency();
    std::cout << "Task will be seprated on " << threadsSize << " threads\n";

    // data vector with row for every thread
    std::vector<std::vector<double>> dataVector;
    double fillVal = 1.1;
    for (auto i = 0; i < threadsSize; ++i, fillVal += 1.1)
    {
        dataVector.push_back(std::vector<double>(ROW_SIZE, fillVal));
    }

    std::vector<std::thread> threadContainer;
    auto start = std::chrono::system_clock::now();
    for (const auto& row : dataVector)
    {
        std::thread thread(&worker, std::ref(row));
        threadContainer.push_back(std::move(thread));
    }
    for (auto& thread : threadContainer)
    {
        thread.join();
    }
    auto end = std::chrono::system_clock::now();
    std::chrono::duration<double> elapsed_seconds = end-start;
    std::cout << "threads time: " << elapsed_seconds.count() << "s\n";

    // main thread only
    g_sum = 0;
    start = std::chrono::system_clock::now();
    for (const auto& row : dataVector)
    {
        const auto vectorSum = std::accumulate(row.begin(), row.end(), 0.0);
        std::cout << "Main Thread adding " << vectorSum << " to final sum ("<< g_sum <<")\n";
        g_sum += vectorSum;
    }
    end = std::chrono::system_clock::now();
    elapsed_seconds = end-start;
    std::cout << "one-thread time: " << elapsed_seconds.count() << "s\n";
}

```

at wandbox (<https://wandbox.org/permlink/qah5auBI3ZoAe7B2>) with 3 logical cores, the multithread timing results are twice better than single-thread.

Is my test correct? Can I assume that, skipping additional implementation time, splitting working task between threads is always better choice?