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;
211 uint32_t pop = 100000;
212 uint32_t total = 1000000;
214 std::string filename =
"";
217 cmd.Usage (
"Benchmark the simulator scheduler.\n" 219 "Event intervals are taken from one of:\n" 220 " an exponential distribution, with mean 100 ns,\n" 221 " an ascii file, given by the --file=\"<filename>\" argument,\n" 222 " or standard input, by the argument --file=\"-\"\n" 223 "In the case of either --file form, the input is expected\n" 224 "to be ascii, giving the relative event times in ns.");
225 cmd.AddValue (
"cal",
"use CalendarSheduler", schedCal);
226 cmd.AddValue (
"heap",
"use HeapScheduler", schedHeap);
227 cmd.AddValue (
"list",
"use ListSheduler", schedList);
228 cmd.AddValue (
"map",
"use MapScheduler (default)", schedMap);
229 cmd.AddValue (
"debug",
"enable debugging output",
g_debug);
230 cmd.AddValue (
"pop",
"event population size (default 1E5)", pop);
231 cmd.AddValue (
"total",
"total number of events to run (default 1E6)", total);
232 cmd.AddValue (
"runs",
"number of runs (default 1)", runs);
233 cmd.AddValue (
"file",
"file of relative event times", filename);
234 cmd.AddValue (
"prec",
"printed output precision",
g_fwidth);
235 cmd.Parse (argc, argv);
242 factory.SetTypeId (
"ns3::CalendarScheduler");
246 factory.SetTypeId (
"ns3::HeapScheduler");
250 factory.SetTypeId (
"ns3::ListScheduler");
255 DEB (
"debugging is ON");
257 LOGME (
"scheduler: " << factory.GetTypeId ().GetName ());
258 LOGME (
"population: " << pop);
259 LOGME (
"total events: " << total);
260 LOGME (
"runs: " << runs);
267 LOG (std::left << std::setw (
g_fwidth) <<
"Run #" <<
268 std::left << std::setw (3 *
g_fwidth) <<
"Inititialization:" <<
269 std::left << std::setw (3 *
g_fwidth) <<
"Simulation:");
271 std::left << std::setw (
g_fwidth) <<
"Time (s)" <<
272 std::left << std::setw (
g_fwidth) <<
"Rate (ev/s)" <<
273 std::left << std::setw (
g_fwidth) <<
"Per (s/ev)" <<
274 std::left << std::setw (
g_fwidth) <<
"Time (s)" <<
275 std::left << std::setw (
g_fwidth) <<
"Rate (ev/s)" <<
276 std::left << std::setw (
g_fwidth) <<
"Per (s/ev)" );
277 LOG (std::setfill (
'-') <<
278 std::right << std::setw (
g_fwidth) <<
" " <<
279 std::right << std::setw (
g_fwidth) <<
" " <<
280 std::right << std::setw (
g_fwidth) <<
" " <<
281 std::right << std::setw (
g_fwidth) <<
" " <<
282 std::right << std::setw (
g_fwidth) <<
" " <<
283 std::right << std::setw (
g_fwidth) <<
" " <<
284 std::right << std::setw (
g_fwidth) <<
" " <<
290 std::cout << std::left << std::setw (
g_fwidth) <<
"(prime)";
295 for (uint32_t i = 0; i < runs; i++)
297 std::cout << std::setw (
g_fwidth) << i;
Simulation virtual time values and global simulation resolution.
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
static EventId Schedule(Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event to expire after delay.
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