21 #include "ns3/core-module.h"
36 void ReadDistribution (std::istream &istream);
37 void SetTotal (uint32_t total);
41 std::vector<uint64_t> m_distribution;
42 std::vector<uint64_t>::const_iterator m_current;
53 Bench::SetTotal (uint32_t total)
59 Bench::ReadDistribution (std::istream &input)
66 uint64_t ns = (uint64_t) (data * 1000000000);
67 m_distribution.push_back (ns);
79 Bench::RunBench (
void)
84 for (std::vector<uint64_t>::const_iterator i = m_distribution.begin ();
85 i != m_distribution.end (); i++)
87 Simulator::Schedule (NanoSeconds (*i), &Bench::Cb,
this);
92 m_current = m_distribution.begin ();
100 "init n=" << m_distribution.size () <<
", time=" << init <<
"s" << std::endl <<
101 "simu n=" << m_n <<
", time=" <<simu <<
"s" << std::endl <<
102 "init " << ((double)m_distribution.size ()) / init <<
" insert/s, avg insert=" <<
103 init / ((
double)m_distribution.size ())<< "s" << std::endl <<
104 "simu " << ((
double)m_n) / simu<< " hold/s, avg hold=" <<
105 simu / ((
double)m_n) << "s" << std::endl
116 if (m_current == m_distribution.end ())
118 m_current = m_distribution.begin ();
122 std::cerr <<
"event at " << Simulator::Now ().GetSeconds () <<
"s" << std::endl;
124 Simulator::Schedule (NanoSeconds (*m_current), &Bench::Cb,
this);
132 std::cout <<
"bench-simulator filename [options]"<<std::endl;
133 std::cout <<
" filename: a string which identifies the input distribution. \"-\" represents stdin." << std::endl;
134 std::cout <<
" Options:"<<std::endl;
135 std::cout <<
" --list: use std::list scheduler"<<std::endl;
136 std::cout <<
" --map: use std::map cheduler"<<std::endl;
137 std::cout <<
" --heap: use Binary Heap scheduler"<<std::endl;
138 std::cout <<
" --debug: enable some debugging"<<std::endl;
141 int main (
int argc,
char *argv[])
143 char const *filename = argv[1];
146 uint32_t total = 20000;
154 if (strcmp (filename,
"-") == 0)
160 input =
new std::ifstream (filename);
165 if (strcmp (
"--list", argv[0]) == 0)
167 factory.
SetTypeId (
"ns3::ListScheduler");
168 Simulator::SetScheduler (factory);
170 else if (strcmp (
"--heap", argv[0]) == 0)
172 factory.
SetTypeId (
"ns3::HeapScheduler");
173 Simulator::SetScheduler (factory);
175 else if (strcmp (
"--map", argv[0]) == 0)
177 factory.
SetTypeId (
"ns3::HeapScheduler");
178 Simulator::SetScheduler (factory);
180 else if (strcmp (
"--calendar", argv[0]) == 0)
182 factory.
SetTypeId (
"ns3::CalendarScheduler");
183 Simulator::SetScheduler (factory);
185 else if (strcmp (
"--debug", argv[0]) == 0)
189 else if (strncmp (
"--total=", argv[0], strlen(
"--total=")) == 0)
191 total = atoi (argv[0]+strlen (
"--total="));
193 else if (strncmp (
"--n=", argv[0], strlen(
"--n=")) == 0)
195 n = atoi (argv[0]+strlen (
"--n="));
202 bench->ReadDistribution (*input);
203 bench->SetTotal (total);
204 for (uint32_t i = 0; i < n; i++)
void SetTypeId(TypeId tid)
measure elapsed time in milliseconds
instantiate subclasses of ns3::Object.
int64_t End(void)
Stop measuring the time since Start() was called.