27 #include "ns3/core-module.h"
35 #define LOG(x) std::cout << x << std::endl
36 #define LOGME(x) LOG (g_me << x)
37 #define DEB(x) if (g_debug) { LOGME (x) ; }
45 Bench (
const uint32_t population,
const uint32_t total)
46 : m_population (population),
58 m_population = population;
85 for (uint32_t i = 0; i < m_population; ++i)
87 Time at = NanoSeconds (m_rand->GetValue ());
92 DEB (
"initialization took " << init <<
"s");
99 DEB (
"run took " << simu <<
"s");
102 std::setw (
g_fwidth) << (m_population / init) <<
103 std::setw (
g_fwidth) << (init / m_population) <<
105 std::setw (
g_fwidth) << (m_count / simu) <<
106 std::setw (
g_fwidth) << (simu / m_count));
115 if (m_count > m_total)
121 Time after = NanoSeconds (m_rand->GetValue ());
134 LOGME (
"using default exponential distribution");
145 LOGME (
"using event distribution from stdin");
150 LOGME (
"using event distribution from " << filename);
151 input =
new std::ifstream (filename.c_str ());
155 std::vector<double> nsValues;
157 while (!input->eof ())
161 uint64_t ns = (uint64_t) (value * 1000000000);
162 nsValues.push_back (ns);
171 LOGME (
"found " << nsValues.size () <<
" entries");
173 drv->SetValueArray (&nsValues[0], nsValues.size ());
182 int main (
int argc,
char *argv[])
185 bool schedCal =
false;
186 bool schedHeap =
false;
187 bool schedList =
false;
188 bool schedMap =
true;
190 uint32_t pop = 100000;
191 uint32_t total = 1000000;
193 std::string filename =
"";
196 cmd.
Usage (
"Benchmark the simulator scheduler.\n"
198 "Event intervals are taken from one of:\n"
199 " an exponential distribution, with mean 100 ns,\n"
200 " an ascii file, given by the --file=\"<filename>\" argument,\n"
201 " or standard input, by the argument --file=\"-\"\n"
202 "In the case of either --file form, the input is expected\n"
203 "to be ascii, giving the relative event times in ns.");
204 cmd.
AddValue (
"cal",
"use CalendarSheduler", schedCal);
205 cmd.
AddValue (
"heap",
"use HeapScheduler", schedHeap);
206 cmd.
AddValue (
"list",
"use ListSheduler", schedList);
207 cmd.
AddValue (
"map",
"use MapScheduler (default)", schedMap);
209 cmd.
AddValue (
"pop",
"event population size (default 1E5)", pop);
210 cmd.
AddValue (
"total",
"total number of events to run (default 1E6)", total);
211 cmd.
AddValue (
"runs",
"number of runs (default 1)", runs);
212 cmd.
AddValue (
"file",
"file of relative event times", filename);
214 cmd.
Parse (argc, argv);
219 if (schedCal) { factory.
SetTypeId (
"ns3::CalendarScheduler"); }
220 if (schedHeap) { factory.
SetTypeId (
"ns3::HeapScheduler"); }
221 if (schedList) { factory.
SetTypeId (
"ns3::ListScheduler"); }
225 DEB (
"debugging is ON");
228 LOGME (
"population: " << pop);
229 LOGME (
"total events: " << total);
230 LOGME (
"runs: " << runs);
237 LOG (std::left << std::setw (
g_fwidth) <<
"Run #" <<
238 std::left << std::setw (3 *
g_fwidth) <<
"Inititialization:" <<
239 std::left << std::setw (3 *
g_fwidth) <<
"Simulation:");
241 std::left << std::setw (
g_fwidth) <<
"Time (s)" <<
242 std::left << std::setw (
g_fwidth) <<
"Rate (ev/s)" <<
243 std::left << std::setw (
g_fwidth) <<
"Per (s/ev)" <<
244 std::left << std::setw (
g_fwidth) <<
"Time (s)" <<
245 std::left << std::setw (
g_fwidth) <<
"Rate (ev/s)" <<
246 std::left << std::setw (
g_fwidth) <<
"Per (s/ev)" );
247 LOG (std::setfill (
'-') <<
248 std::right << std::setw (
g_fwidth) <<
" " <<
249 std::right << std::setw (
g_fwidth) <<
" " <<
250 std::right << std::setw (
g_fwidth) <<
" " <<
251 std::right << std::setw (
g_fwidth) <<
" " <<
252 std::right << std::setw (
g_fwidth) <<
" " <<
253 std::right << std::setw (
g_fwidth) <<
" " <<
254 std::right << std::setw (
g_fwidth) <<
" " <<
260 std::cout << std::left << std::setw (
g_fwidth) <<
"(prime)";
265 for (uint32_t i = 0; i < runs; i++)
267 std::cout << std::setw (
g_fwidth) << i;
TypeId GetTypeId(void) const
keep track of time values and allow control of global simulation resolution
Ptr< RandomVariableStream > m_rand
static void Run(void)
Run the simulation until one of:
void SetTypeId(TypeId tid)
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
Schedule an event to expire at the relative time "time" is reached.
Ptr< RandomVariableStream > GetRandomStream(std::string filename)
std::string GetName() const
Get the program name.
void Usage(const std::string usage)
Supply the program usage and documentation.
measure elapsed time in milliseconds
Bench(const uint32_t population, const uint32_t total)
void SetPopulation(const uint32_t population)
void Start(void)
Start a measure.
Parse command-line arguments.
static void Destroy(void)
Every event scheduled by the Simulator::insertAtDestroy method is invoked.
int main(int argc, char *argv[])
void SetRandomStream(Ptr< RandomVariableStream > stream)
std::string GetName(void) const
static void SetScheduler(ObjectFactory schedulerFactory)
static Time Now(void)
Return the "current simulation time".
instantiate subclasses of ns3::Object.
void AddValue(const std::string &name, const std::string &help, T &value)
Add a program argument, assigning to POD.
void Parse(int argc, char *argv[])
Parse the program arguments.
Hold a floating point type.
void SetAttribute(std::string name, const AttributeValue &value)
int64_t End(void)
Stop measuring the time since Start() was called.
void SetTotal(const uint32_t total)