Files
ns-3-dev/utils/bench-simulator.cc
T
Tom Henderson c26396ec5d merge src/simulator into src/core; move src/core to new module layout
--HG--
rename : src/core/abort.h => src/core/model/abort.h
rename : src/core/assert.h => src/core/model/assert.h
rename : src/core/attribute-accessor-helper.h => src/core/model/attribute-accessor-helper.h
rename : src/core/attribute-helper.h => src/core/model/attribute-helper.h
rename : src/core/attribute-list.cc => src/core/model/attribute-list.cc
rename : src/core/attribute-list.h => src/core/model/attribute-list.h
rename : src/core/attribute.cc => src/core/model/attribute.cc
rename : src/core/attribute.h => src/core/model/attribute.h
rename : src/core/boolean.cc => src/core/model/boolean.cc
rename : src/core/boolean.h => src/core/model/boolean.h
rename : src/core/breakpoint.cc => src/core/model/breakpoint.cc
rename : src/core/breakpoint.h => src/core/model/breakpoint.h
rename : src/simulator/cairo-wideint-private.h => src/core/model/cairo-wideint-private.h
rename : src/simulator/cairo-wideint.c => src/core/model/cairo-wideint.c
rename : src/simulator/calendar-scheduler.cc => src/core/model/calendar-scheduler.cc
rename : src/simulator/calendar-scheduler.h => src/core/model/calendar-scheduler.h
rename : src/core/callback.cc => src/core/model/callback.cc
rename : src/core/callback.h => src/core/model/callback.h
rename : src/core/command-line.cc => src/core/model/command-line.cc
rename : src/core/command-line.h => src/core/model/command-line.h
rename : src/core/config.cc => src/core/model/config.cc
rename : src/core/config.h => src/core/model/config.h
rename : src/core/default-deleter.h => src/core/model/default-deleter.h
rename : src/simulator/default-simulator-impl.cc => src/core/model/default-simulator-impl.cc
rename : src/simulator/default-simulator-impl.h => src/core/model/default-simulator-impl.h
rename : src/core/deprecated.h => src/core/model/deprecated.h
rename : src/core/double.cc => src/core/model/double.cc
rename : src/core/double.h => src/core/model/double.h
rename : src/core/empty.h => src/core/model/empty.h
rename : src/core/enum.cc => src/core/model/enum.cc
rename : src/core/enum.h => src/core/model/enum.h
rename : src/simulator/event-id.cc => src/core/model/event-id.cc
rename : src/simulator/event-id.h => src/core/model/event-id.h
rename : src/simulator/event-impl.cc => src/core/model/event-impl.cc
rename : src/simulator/event-impl.h => src/core/model/event-impl.h
rename : src/core/fatal-error.h => src/core/model/fatal-error.h
rename : src/core/fatal-impl.cc => src/core/model/fatal-impl.cc
rename : src/core/fatal-impl.h => src/core/model/fatal-impl.h
rename : src/core/global-value.cc => src/core/model/global-value.cc
rename : src/core/global-value.h => src/core/model/global-value.h
rename : src/simulator/heap-scheduler.cc => src/core/model/heap-scheduler.cc
rename : src/simulator/heap-scheduler.h => src/core/model/heap-scheduler.h
rename : src/simulator/high-precision-128.cc => src/core/model/high-precision-128.cc
rename : src/simulator/high-precision-128.h => src/core/model/high-precision-128.h
rename : src/simulator/high-precision-cairo.cc => src/core/model/high-precision-cairo.cc
rename : src/simulator/high-precision-cairo.h => src/core/model/high-precision-cairo.h
rename : src/simulator/high-precision-double.h => src/core/model/high-precision-double.h
rename : src/simulator/high-precision.cc => src/core/model/high-precision.cc
rename : src/simulator/high-precision.h => src/core/model/high-precision.h
rename : src/core/int-to-type.h => src/core/model/int-to-type.h
rename : src/core/integer.cc => src/core/model/integer.cc
rename : src/core/integer.h => src/core/model/integer.h
rename : src/simulator/list-scheduler.cc => src/core/model/list-scheduler.cc
rename : src/simulator/list-scheduler.h => src/core/model/list-scheduler.h
rename : src/core/log.cc => src/core/model/log.cc
rename : src/core/log.h => src/core/model/log.h
rename : src/simulator/make-event.cc => src/core/model/make-event.cc
rename : src/simulator/make-event.h => src/core/model/make-event.h
rename : src/simulator/map-scheduler.cc => src/core/model/map-scheduler.cc
rename : src/simulator/map-scheduler.h => src/core/model/map-scheduler.h
rename : src/core/names.cc => src/core/model/names.cc
rename : src/core/names.h => src/core/model/names.h
rename : src/simulator/ns2-calendar-scheduler.cc => src/core/model/ns2-calendar-scheduler.cc
rename : src/simulator/ns2-calendar-scheduler.h => src/core/model/ns2-calendar-scheduler.h
rename : src/simulator/nstime.h => src/core/model/nstime.h
rename : src/core/object-base.cc => src/core/model/object-base.cc
rename : src/core/object-base.h => src/core/model/object-base.h
rename : src/core/object-factory.cc => src/core/model/object-factory.cc
rename : src/core/object-factory.h => src/core/model/object-factory.h
rename : src/core/object-vector.cc => src/core/model/object-vector.cc
rename : src/core/object-vector.h => src/core/model/object-vector.h
rename : src/core/object.cc => src/core/model/object.cc
rename : src/core/object.h => src/core/model/object.h
rename : src/core/pointer.cc => src/core/model/pointer.cc
rename : src/core/pointer.h => src/core/model/pointer.h
rename : src/core/ptr.h => src/core/model/ptr.h
rename : src/core/random-variable.cc => src/core/model/random-variable.cc
rename : src/core/random-variable.h => src/core/model/random-variable.h
rename : src/simulator/realtime-simulator-impl.cc => src/core/model/realtime-simulator-impl.cc
rename : src/simulator/realtime-simulator-impl.h => src/core/model/realtime-simulator-impl.h
rename : src/core/ref-count-base.cc => src/core/model/ref-count-base.cc
rename : src/core/ref-count-base.h => src/core/model/ref-count-base.h
rename : src/core/rng-stream.cc => src/core/model/rng-stream.cc
rename : src/core/rng-stream.h => src/core/model/rng-stream.h
rename : src/simulator/scheduler.cc => src/core/model/scheduler.cc
rename : src/simulator/scheduler.h => src/core/model/scheduler.h
rename : src/core/simple-ref-count.h => src/core/model/simple-ref-count.h
rename : src/simulator/simulation-singleton.h => src/core/model/simulation-singleton.h
rename : src/simulator/simulator-impl.cc => src/core/model/simulator-impl.cc
rename : src/simulator/simulator-impl.h => src/core/model/simulator-impl.h
rename : src/simulator/simulator.cc => src/core/model/simulator.cc
rename : src/simulator/simulator.h => src/core/model/simulator.h
rename : src/core/singleton.h => src/core/model/singleton.h
rename : src/core/string.cc => src/core/model/string.cc
rename : src/core/string.h => src/core/model/string.h
rename : src/simulator/synchronizer.cc => src/core/model/synchronizer.cc
rename : src/simulator/synchronizer.h => src/core/model/synchronizer.h
rename : src/core/system-condition.h => src/core/model/system-condition.h
rename : src/core/system-mutex.h => src/core/model/system-mutex.h
rename : src/core/system-thread.h => src/core/model/system-thread.h
rename : src/core/system-wall-clock-ms.h => src/core/model/system-wall-clock-ms.h
rename : src/core/test.cc => src/core/model/test.cc
rename : src/core/test.h => src/core/model/test.h
rename : src/simulator/time-base.cc => src/core/model/time-base.cc
rename : src/simulator/time-base.h => src/core/model/time-base.h
rename : src/simulator/time.cc => src/core/model/time.cc
rename : src/simulator/timer-impl.h => src/core/model/timer-impl.h
rename : src/simulator/timer.cc => src/core/model/timer.cc
rename : src/simulator/timer.h => src/core/model/timer.h
rename : src/core/trace-source-accessor.cc => src/core/model/trace-source-accessor.cc
rename : src/core/trace-source-accessor.h => src/core/model/trace-source-accessor.h
rename : src/core/traced-callback.h => src/core/model/traced-callback.h
rename : src/core/traced-value.h => src/core/model/traced-value.h
rename : src/core/type-id.cc => src/core/model/type-id.cc
rename : src/core/type-id.h => src/core/model/type-id.h
rename : src/core/type-name.cc => src/core/model/type-name.cc
rename : src/core/type-name.h => src/core/model/type-name.h
rename : src/core/type-traits.h => src/core/model/type-traits.h
rename : src/core/uinteger.cc => src/core/model/uinteger.cc
rename : src/core/uinteger.h => src/core/model/uinteger.h
rename : src/simulator/unix-fd-reader.cc => src/core/model/unix-fd-reader.cc
rename : src/simulator/unix-fd-reader.h => src/core/model/unix-fd-reader.h
rename : src/core/unix-system-condition.cc => src/core/model/unix-system-condition.cc
rename : src/core/unix-system-mutex.cc => src/core/model/unix-system-mutex.cc
rename : src/core/unix-system-thread.cc => src/core/model/unix-system-thread.cc
rename : src/core/unix-system-wall-clock-ms.cc => src/core/model/unix-system-wall-clock-ms.cc
rename : src/core/vector.cc => src/core/model/vector.cc
rename : src/core/vector.h => src/core/model/vector.h
rename : src/simulator/wall-clock-synchronizer.cc => src/core/model/wall-clock-synchronizer.cc
rename : src/simulator/wall-clock-synchronizer.h => src/core/model/wall-clock-synchronizer.h
rename : src/simulator/watchdog.cc => src/core/model/watchdog.cc
rename : src/simulator/watchdog.h => src/core/model/watchdog.h
rename : src/core/win32-system-wall-clock-ms.cc => src/core/model/win32-system-wall-clock-ms.cc
rename : src/core/attribute-test-suite.cc => src/core/test/attribute-test-suite.cc
rename : src/core/callback-test-suite.cc => src/core/test/callback-test-suite.cc
rename : src/core/names-test-suite.cc => src/core/test/names-test-suite.cc
rename : src/core/ptr-test-suite.cc => src/core/test/ptr-test-suite.cc
rename : src/core/rng-test-suite.cc => src/core/test/rng-test-suite.cc
rename : src/core/traced-callback-test-suite.cc => src/core/test/traced-callback-test-suite.cc
rename : src/core/type-traits-test-suite.cc => src/core/test/type-traits-test-suite.cc
2011-02-18 16:05:39 -08:00

212 lines
5.1 KiB
C++

/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2006 INRIA
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
*/
#include "ns3/core-module.h"
#include "ns3/core-module.h"
#include <iostream>
#include <fstream>
#include <vector>
#include <string.h>
using namespace ns3;
bool g_debug = false;
class Bench
{
public:
Bench ();
void ReadDistribution (std::istream &istream);
void SetTotal (uint32_t total);
void RunBench (void);
private:
void Cb (void);
std::vector<uint64_t> m_distribution;
std::vector<uint64_t>::const_iterator m_current;
uint32_t m_n;
uint32_t m_total;
};
Bench::Bench ()
: m_n (0),
m_total (0)
{}
void
Bench::SetTotal (uint32_t total)
{
m_total = total;
}
void
Bench::ReadDistribution (std::istream &input)
{
double data;
while (!input.eof ())
{
if (input >> data)
{
uint64_t ns = (uint64_t) (data * 1000000000);
m_distribution.push_back (ns);
}
else
{
input.clear ();
std::string line;
input >> line;
}
}
}
void
Bench::RunBench (void)
{
SystemWallClockMs time;
double init, simu;
time.Start ();
for (std::vector<uint64_t>::const_iterator i = m_distribution.begin ();
i != m_distribution.end (); i++)
{
Simulator::Schedule (NanoSeconds (*i), &Bench::Cb, this);
}
init = time.End ();
init /= 1000;
m_current = m_distribution.begin ();
time.Start ();
Simulator::Run ();
simu = time.End ();
simu /= 1000;
std::cout <<
"init n=" << m_distribution.size () << ", time=" << init << "s" << std::endl <<
"simu n=" << m_n << ", time=" <<simu << "s" << std::endl <<
"init " << ((double)m_distribution.size ()) / init << " insert/s, avg insert=" <<
init / ((double)m_distribution.size ())<< "s" << std::endl <<
"simu " << ((double)m_n) / simu<< " hold/s, avg hold=" <<
simu / ((double)m_n) << "s" << std::endl
;
}
void
Bench::Cb (void)
{
if (m_n > m_total)
{
return;
}
if (m_current == m_distribution.end ())
{
m_current = m_distribution.begin ();
}
if (g_debug)
{
std::cerr << "event at " << Simulator::Now ().GetSeconds () << "s" << std::endl;
}
Simulator::Schedule (NanoSeconds (*m_current), &Bench::Cb, this);
m_current++;
m_n++;
}
void
PrintHelp (void)
{
std::cout << "bench-simulator filename [options]"<<std::endl;
std::cout << " filename: a string which identifies the input distribution. \"-\" represents stdin." << std::endl;
std::cout << " Options:"<<std::endl;
std::cout << " --list: use std::list scheduler"<<std::endl;
std::cout << " --map: use std::map cheduler"<<std::endl;
std::cout << " --heap: use Binary Heap scheduler"<<std::endl;
std::cout << " --debug: enable some debugging"<<std::endl;
}
int main (int argc, char *argv[])
{
char const *filename = argv[1];
std::istream *input;
uint32_t n = 1;
uint32_t total = 20000;
if (argc == 1)
{
PrintHelp ();
return 0;
}
argc-=2;
argv+= 2;
if (strcmp (filename, "-") == 0)
{
input = &std::cin;
}
else
{
input = new std::ifstream (filename);
}
while (argc > 0)
{
ObjectFactory factory;
if (strcmp ("--list", argv[0]) == 0)
{
factory.SetTypeId ("ns3::ListScheduler");
Simulator::SetScheduler (factory);
}
else if (strcmp ("--heap", argv[0]) == 0)
{
factory.SetTypeId ("ns3::HeapScheduler");
Simulator::SetScheduler (factory);
}
else if (strcmp ("--map", argv[0]) == 0)
{
factory.SetTypeId ("ns3::HeapScheduler");
Simulator::SetScheduler (factory);
}
else if (strcmp ("--calendar", argv[0]) == 0)
{
factory.SetTypeId ("ns3::CalendarScheduler");
Simulator::SetScheduler (factory);
}
else if (strcmp ("--debug", argv[0]) == 0)
{
g_debug = true;
}
else if (strncmp ("--total=", argv[0], strlen("--total=")) == 0)
{
total = atoi (argv[0]+strlen ("--total="));
}
else if (strncmp ("--n=", argv[0], strlen("--n=")) == 0)
{
n = atoi (argv[0]+strlen ("--n="));
}
argc--;
argv++;
}
Bench *bench = new Bench ();
bench->ReadDistribution (*input);
bench->SetTotal (total);
for (uint32_t i = 0; i < n; i++)
{
bench->RunBench ();
}
return 0;
}