|
Boost : |
Subject: Re: [boost] [Fibers] Performance
From: Hartmut Kaiser (hartmut.kaiser_at_[hidden])
Date: 2014-01-14 13:42:53
> > 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)
I'd be disappointed if the overheads imposed by Boost.Fiber are only 2-3
times smaller than for kernel threads. I'd expect it to impose at least 10
times, if not 15-20 times less overheads than kernel threads (at least
that's the numbers we're seeing from HPX).
Regards Hartmut
---------------
http://boost-spirit.com
http://stellar.cct.lsu.edu
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk