|
Boost Users : |
Subject: Re: [Boost-users] [Asio]Question about error_code when socket::close
From: Comet (cometliao_at_[hidden])
Date: 2010-05-17 06:53:50
> void Read() {
> // this line is very slow,
> // because
boost::bind(&Session::HandleRead,shared_from_this(), ...)
> // causes extra new/delete operations
My test result:
---------------------------------- raw ptr version
------------------------
a.cc:
class A
{
public:
void f() {}
};
int main() {
A a;
boost::function<void ()> f;
for (size_t i = 0; i < 100000000; ++i) {
f = boost::bind(&A::f, &a);
}
}
gcc a.cc -O2
time ./a.out
real 0m1.235s
user 0m1.232s
sys 0m0.000s
------------------------------------ shared_ptr version
----------------------
a.cc:
class A
{
public:
static void f(boost::weak_ptr<A>) {}
};
int main() {
boost::shared_ptr<A> a = boost::make_shared<A>();
boost::function<void ()> f;
for (size_t i = 0; i < 100000000; ++i) {
f = boost::bind(&A::f, a);
}
}
gcc a.cc -O2
time ./a.out
real 0m25.925s
user 0m25.898s
sys 0m0.000s
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net