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");
194 drv->SetValueArray (&nsValues[0], nsValues.size ());
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;
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Simulation virtual time values and global simulation resolution.
AttributeValue implementation for Boolean.
Ptr< RandomVariableStream > m_rand
random variable
void RunBench(void)
Run function.
ns3::StringValue attribute value declarations.
static void Run(void)
Run the simulation.
Ptr< RandomVariableStream > GetRandomStream(std::string filename)
Measure elapsed wall clock time in milliseconds.
Bench(const uint32_t population, const uint32_t total)
constructor
void SetPopulation(const uint32_t population)
Set population function.
Time NanoSeconds(uint64_t value)
Construct a Time in the indicated unit.
void Start(void)
Start a measure.
uint32_t m_population
population
Parse command-line arguments.
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void SetRandomStream(Ptr< RandomVariableStream > stream)
Set random stream.
static void SetScheduler(ObjectFactory schedulerFactory)
Set the scheduler type with an ObjectFactory.
static Time Now(void)
Return the current simulation virtual time.
Instantiate subclasses of ns3::Object.
This class can be used to hold variables of floating point type such as 'double' or 'float'...
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
int64_t End(void)
Stop measuring the time since Start() was called.
void SetTotal(const uint32_t total)
Set total function.
void Cb(void)
callback function