Boost logo

Boost :

Subject: Re: [boost] [Fibers] Performance
From: Oliver Kowalke (oliver.kowalke_at_[hidden])
Date: 2014-01-14 06:41:31


2014/1/14 Antony Polukhin <antoshkka_at_[hidden]>

> Pseudocode:
>
> void foo(){}
> const unsigned N = 1000;
>
> // Test #1
> timer start
> for (unsigned i = 0; i < N; ++i) {
> fiber f(&foo);
> f.join();
> }
>
> cout << "Fibers: " << timer stop;
>
>
> timer start
> for (unsigned i = 0; i < N; ++i) {
> boost::thread f(&foo);
> f.join();
> }
>
> cout << "Threads: " << timer stop;
>
> // Test #2
> timer start
> for (unsigned i = 0; i < N; ++i) {
> fiber f1(&foo), f2(&foo), f3(&foo), f4(&foo), f5(&foo);
> f1.join(); f2.join(); f3.join(); f4.join(); f5.join();
> }
>
> cout << "Fibers: " << timer stop;
>
> timer start
> for (unsigned i = 0; i < N; ++i) {
> boost::thread f1(&foo), f2(&foo), f3(&foo), f4(&foo), f5(&foo);
> f1.join(); f2.join(); f3.join(); f4.join(); f5.join();
> }
>
> cout << "Threads: " << timer stop;
>
> // Test #3
> timer start
> for (unsigned i = 0; i < N; ++i) {
> fiber(&foo).detach();
> }
>
> cout << "Fibers: " << timer stop;
>
> timer start
> for (unsigned i = 0; i < N; ++i) {
> boost::thread(&foo).detach();
> }
>
> cout << "Threads: " << timer stop;
>

I did a quick hack and the code using fibers is 2-3 times faster than the
threads.
boost.fiber does not contain the suggested optimizations (like replacing
stl containers)


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk