From b3d1e901328a3da19ba959d18c13e277dc7118b3 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 17 May 2007 16:45:03 +0200 Subject: [PATCH] add benchmark by gustavo --- SConstruct | 6 ++++++ utils/bench-object.cc | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 utils/bench-object.cc diff --git a/SConstruct b/SConstruct index 3cb51eb7a..de8e80656 100644 --- a/SConstruct +++ b/SConstruct @@ -340,6 +340,12 @@ run_tests.set_executable() run_tests.add_deps(['core', 'simulator', 'common']) run_tests.add_source('run-tests.cc') +bench_object = build.Ns3Module('bench-object', 'utils') +ns3.add(bench_object) +bench_object.set_executable() +bench_object.add_deps(['core']) +bench_object.add_source('bench-object.cc') + bench_packets = build.Ns3Module('bench-packets', 'utils') #ns3.add(bench_packets) bench_packets.set_executable() diff --git a/utils/bench-object.cc b/utils/bench-object.cc new file mode 100644 index 000000000..4a6a8ca3d --- /dev/null +++ b/utils/bench-object.cc @@ -0,0 +1,43 @@ +#include +#include +#include "ns3/interface-object.h" + +using namespace ns3; + +class BaseA : public ns3::InterfaceObject +{ +public: + static const ns3::MyInterfaceId iid; + BaseA () + { + SetInterfaceId (BaseA::iid); + } + virtual void Dispose (void) {} +}; + +const ns3::MyInterfaceId BaseA::iid = +ns3::MakeInterfaceId ("BaseABench", InterfaceObject::iid); + + + +int main (int argc, char *argv[]) +{ + int nobjects = atoi (argv[1]); + int nswaps = atoi (argv[2]); + + std::vector< Ptr > objlist; + + for (int i = 0; i < nobjects; ++i) + objlist.push_back (MakeNewObject ()); + + for (int swapCounter = nswaps; swapCounter; --swapCounter) + { + int x1 = swapCounter % nobjects; + int x2 = (swapCounter+1) % nobjects; + Ptr obj1 = objlist[x1]; + Ptr obj2 = objlist[x2]; + objlist[x2] = obj1; + objlist[x1] = obj2; + } +} +