Welcome to mirror list, hosted at ThFree Co, Russian Federation.

benchmark_asio.cpp « example « attic - github.com/windirstat/llfio.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 45de6e45e8538e24da4f70fce52ac43381a74a06 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "afio_pch.hpp"

/*  My Intel Core i7 3770K running Windows 8 x64: 2591360 closures/sec
    My Intel Core i7 3770K running     Linux x64: 1611040 closures/sec (4 threads)
*/

static boost::afio::atomic<size_t> togo(0);
static int callback()
{
#if 0
    Sleep(0);
#endif
    --togo;
    return 1;
};
int main(void)
{
    using namespace boost::afio;
    typedef chrono::duration<double, ratio<1, 1>> secs_type;
    auto threadpool=process_threadpool();
    auto begin=chrono::high_resolution_clock::now();
    while(chrono::duration_cast<secs_type>(chrono::high_resolution_clock::now()-begin).count()<3);
    
    atomic<size_t> threads(0);
#if 0
    std::cout << "Attach profiler now and hit Return" << std::endl;
    getchar();
#endif
    begin=chrono::high_resolution_clock::now();
#pragma omp parallel
    {
        ++threads;
        for(size_t n=0; n<5000000; n++)
        {
            ++togo;
            threadpool->enqueue(callback);
        }
    }
    while(togo)
        this_thread::sleep_for(chrono::milliseconds(1));
    auto end=chrono::high_resolution_clock::now();
    auto diff=chrono::duration_cast<secs_type>(end-begin);
    std::cout << "It took " << diff.count() << " secs to execute " << (5000000*threads) << " closures which is " << (5000000*threads/diff.count()) << " closures/sec" << std::endl;
    std::cout << "\nPress Return to exit ..." << std::endl;
    getchar();
    return 0;
}