[Ns-developers] A Reason for Slowness of NS3
Mathieu Lacage
mathieu.lacage at sophia.inria.fr
Sat Feb 14 10:47:15 PST 2009
On Sat, 2009-02-14 at 08:34 -0800, Tom Henderson wrote:
> Do you understand yet why Calendar is not doing better than Map in most
> (all?) of our scenarios?
No. I looked at the calendar code carefully and I believe that I did not
introduce any performance bug in the calendar code proper. Someone who
knows the original ns-2 code better (hint!) should probably try to
review what I did in search of anything I might have screwed up.
> - TypeId tid = GetTypeId();
> + const TypeId& tid = GetTypeId();
>
> won't the copy in this case just be optimized away by compilers, making
> return by reference here unnecessary? Does gcc optimize this case?
1) The answer to this question does not really matter because return a
const reference is simply not an option from a maintenance point of view
so, arguing about whether or not it is necessary from a performance
point of view is not really useful.
2) but, yes, from a purely academic point of view, you are right, gcc
optimizes this case:
-bash-3.2$ cat test.cc
#include "simple.h"
int main (int argc, char *argv[])
{
Simple s = Do ();
s.Foo (2);
return 0;
}
-bash-3.2$ cat simple.h
class Simple
{
public:
Simple (const Simple &o);
Simple ();
~ Simple ();
Simple &operator = (const Simple &o);
void Foo (int v) ;
private:
int m_v;
};
Simple Do (void);
-bash-3.2$
-bash-3.2$ cat simple.cc
#include "simple.h"
Simple::Simple (const Simple &o) {}
Simple::Simple () {}
Simple::~ Simple () {}
Simple &
Simple::operator = (const Simple &o)
{}
void Simple::Foo (int v) {m_v = v;}
Simple Do (void)
{
return Simple ();
}
-bash-3.2$ g++ -O3 ./test.cc ./simple.cc
-bash-3.2$ objdump -d ./a.out |c++filt -t |less
00000000004005e0 <main>:
4005e0: 48 89 5c 24 f0 mov %rbx,-0x10(%rsp)
4005e5: 48 89 6c 24 f8 mov %rbp,-0x8(%rsp)
4005ea: 48 83 ec 28 sub $0x28,%rsp
4005ee: 48 89 e7 mov %rsp,%rdi
4005f1: e8 ba 00 00 00 callq 4006b0 <Do()>
4005f6: be 02 00 00 00 mov $0x2,%esi
4005fb: 48 89 e7 mov %rsp,%rdi
4005fe: e8 9d 00 00 00 callq 4006a0 <Simple::Foo(int)>
See that there is no call to Simple::Simple(const Simple&);
Mathieu
More information about the Ns-developers
mailing list