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); }
51 Bench (
const uint32_t population,
const uint32_t total)
52 : m_population (population),
73 m_population = population;
103 DEB (
"initializing");
108 for (uint32_t i = 0; i < m_population; ++i)
115 DEB (
"initialization took " << init <<
"s");
122 DEB (
"run took " << simu <<
"s");
125 std::setw (
g_fwidth) << (m_population / init) <<
126 std::setw (
g_fwidth) << (init / m_population) <<
128 std::setw (
g_fwidth) << (m_count / simu) <<
129 std::setw (
g_fwidth) << (simu / m_count));
136 if (m_count >= m_total)
155 LOGME (
"using default exponential distribution");
166 LOGME (
"using event distribution from stdin");
171 LOGME (
"using event distribution from " << filename);
172 input =
new std::ifstream (filename.c_str ());
176 std::vector<double> nsValues;
178 while (!input->eof ())
182 uint64_t ns = (uint64_t) (value * 1000000000);
183 nsValues.push_back (ns);
192 LOGME (
"found " << nsValues.size () <<
" entries");
203 int main (
int argc,
char *argv[])
206 bool schedCal =
false;
207 bool schedHeap =
false;
208 bool schedList =
false;
209 bool schedMap =
true;
210 bool schedPriorityQueue =
false;
212 uint32_t pop = 100000;
213 uint32_t total = 1000000;
215 std::string filename =
"";
219 cmd.Usage (
"Benchmark the simulator scheduler.\n"
221 "Event intervals are taken from one of:\n"
222 " an exponential distribution, with mean 100 ns,\n"
223 " an ascii file, given by the --file=\"<filename>\" argument,\n"
224 " or standard input, by the argument --file=\"-\"\n"
225 "In the case of either --file form, the input is expected\n"
226 "to be ascii, giving the relative event times in ns.");
227 cmd.AddValue (
"cal",
"use CalendarSheduler", schedCal);
228 cmd.AddValue (
"calrev",
"reverse ordering in the CalendarScheduler", calRev);
229 cmd.AddValue (
"heap",
"use HeapScheduler", schedHeap);
230 cmd.AddValue (
"list",
"use ListSheduler", schedList);
231 cmd.AddValue (
"map",
"use MapScheduler (default)", schedMap);
232 cmd.AddValue (
"pri",
"use PriorityQueue", schedPriorityQueue);
233 cmd.AddValue (
"debug",
"enable debugging output",
g_debug);
234 cmd.AddValue (
"pop",
"event population size (default 1E5)", pop);
235 cmd.AddValue (
"total",
"total number of events to run (default 1E6)", total);
236 cmd.AddValue (
"runs",
"number of runs (default 1)", runs);
237 cmd.AddValue (
"file",
"file of relative event times", filename);
238 cmd.AddValue (
"prec",
"printed output precision",
g_fwidth);
239 cmd.Parse (argc, argv);
246 factory.SetTypeId (
"ns3::CalendarScheduler");
251 factory.SetTypeId (
"ns3::HeapScheduler");
255 factory.SetTypeId (
"ns3::ListScheduler");
257 if (schedPriorityQueue)
259 factory.SetTypeId (
"ns3::PriorityQueueScheduler");
265 DEB (
"debugging is ON");
270 order =
": insertion order: " + std::string (calRev ?
"reverse" :
"normal");
272 LOGME (
"scheduler: " << factory.GetTypeId ().GetName () << order);
273 LOGME (
"population: " << pop);
274 LOGME (
"total events: " << total);
275 LOGME (
"runs: " << runs);
282 LOG (std::left << std::setw (
g_fwidth) <<
"Run #" <<
283 std::left << std::setw (3 *
g_fwidth) <<
"Initialization:" <<
284 std::left << std::setw (3 *
g_fwidth) <<
"Simulation:");
286 std::left << std::setw (
g_fwidth) <<
"Time (s)" <<
287 std::left << std::setw (
g_fwidth) <<
"Rate (ev/s)" <<
288 std::left << std::setw (
g_fwidth) <<
"Per (s/ev)" <<
289 std::left << std::setw (
g_fwidth) <<
"Time (s)" <<
290 std::left << std::setw (
g_fwidth) <<
"Rate (ev/s)" <<
291 std::left << std::setw (
g_fwidth) <<
"Per (s/ev)" );
292 LOG (std::setfill (
'-') <<
293 std::right << std::setw (
g_fwidth) <<
" " <<
294 std::right << std::setw (
g_fwidth) <<
" " <<
295 std::right << std::setw (
g_fwidth) <<
" " <<
296 std::right << std::setw (
g_fwidth) <<
" " <<
297 std::right << std::setw (
g_fwidth) <<
" " <<
298 std::right << std::setw (
g_fwidth) <<
" " <<
299 std::right << std::setw (
g_fwidth) <<
" " <<
305 std::cout << std::left << std::setw (
g_fwidth) <<
"(prime)";
310 for (uint32_t i = 0; i < runs; i++)
312 std::cout << std::setw (
g_fwidth) << i;