|
|
| 33 |
|
33 |
|
| 34 |
std::string g_me; |
34 |
std::string g_me; |
| 35 |
#define LOG(x) std::cout << x << std::endl |
35 |
#define LOG(x) std::cout << x << std::endl |
| 36 |
#define LOGME(x) LOG (g_me << x) |
36 |
#define LOGME(x) LOG (g_me << x) |
| 37 |
#define DEB(x) if (g_debug) { LOGME (x) ; } |
37 |
#define DEB(x) if (g_debug) { LOGME (x); } |
| 38 |
|
38 |
|
| 39 |
// Output field width |
39 |
// Output field width |
| 40 |
int g_fwidth = 6; |
40 |
int g_fwidth = 6; |
| 41 |
|
41 |
|
| 42 |
class Bench |
42 |
class Bench |
| 43 |
{ |
43 |
{ |
| 44 |
public: |
44 |
public: |
| 45 |
Bench (const uint32_t population, const uint32_t total) |
45 |
Bench (const uint32_t population, const uint32_t total) |
| 46 |
: m_population (population), |
46 |
: m_population (population), |
| 47 |
m_total (total), |
47 |
m_total (total), |
| 48 |
m_count (0) |
48 |
m_count (0) |
| 49 |
{ }; |
49 |
{ |
| 50 |
|
50 |
} |
|
|
51 |
|
| 51 |
void SetRandomStream (Ptr<RandomVariableStream> stream) |
52 |
void SetRandomStream (Ptr<RandomVariableStream> stream) |
| 52 |
{ |
53 |
{ |
| 53 |
m_rand = stream; |
54 |
m_rand = stream; |
| 54 |
} |
55 |
} |
| 55 |
|
56 |
|
| 56 |
void SetPopulation (const uint32_t population) |
57 |
void SetPopulation (const uint32_t population) |
| 57 |
{ |
58 |
{ |
| 58 |
m_population = population; |
59 |
m_population = population; |
| 59 |
} |
60 |
} |
| 60 |
|
61 |
|
| 61 |
void SetTotal (const uint32_t total) |
62 |
void SetTotal (const uint32_t total) |
| 62 |
{ |
63 |
{ |
| 63 |
m_total = total; |
64 |
m_total = total; |
| 64 |
} |
65 |
} |
| 65 |
|
66 |
|
| 66 |
void RunBench (void); |
67 |
void RunBench (void); |
| 67 |
private: |
68 |
private: |
| 68 |
void Cb (void); |
69 |
void Cb (void); |
| 69 |
|
70 |
|
| 70 |
Ptr<RandomVariableStream> m_rand; |
71 |
Ptr<RandomVariableStream> m_rand; |
| 71 |
uint32_t m_population; |
72 |
uint32_t m_population; |
| 72 |
uint32_t m_total; |
73 |
uint32_t m_total; |
|
|
| 74 |
}; |
75 |
}; |
| 75 |
|
76 |
|
| 76 |
void |
77 |
void |
| 77 |
Bench::RunBench (void) |
78 |
Bench::RunBench (void) |
| 78 |
{ |
79 |
{ |
| 79 |
SystemWallClockMs time; |
80 |
SystemWallClockMs time; |
| 80 |
double init, simu; |
81 |
double init, simu; |
|
Lines 112-118
Bench::RunBench (void)
|
Link Here
|
|---|
|
| 112 |
void |
113 |
void |
| 113 |
Bench::Cb (void) |
114 |
Bench::Cb (void) |
| 114 |
{ |
115 |
{ |
| 115 |
if (m_count >= m_total) |
116 |
if (m_count >= m_total) |
| 116 |
{ |
117 |
{ |
| 117 |
return; |
118 |
return; |
| 118 |
} |
119 |
} |
|
Lines 128-134
Ptr<RandomVariableStream>
|
Link Here
|
|---|
|
| 128 |
GetRandomStream (std::string filename) |
129 |
GetRandomStream (std::string filename) |
| 129 |
{ |
130 |
{ |
| 130 |
Ptr<RandomVariableStream> stream = 0; |
131 |
Ptr<RandomVariableStream> stream = 0; |
| 131 |
|
132 |
|
| 132 |
if (filename == "") |
133 |
if (filename == "") |
| 133 |
{ |
134 |
{ |
| 134 |
LOGME ("using default exponential distribution"); |
135 |
LOGME ("using default exponential distribution"); |
|
Lines 138-150
GetRandomStream (std::string filename)
|
Link Here
|
|---|
|
| 138 |
} |
139 |
} |
| 139 |
else |
140 |
else |
| 140 |
{ |
141 |
{ |
| 141 |
std::istream *input; |
142 |
std::istream *input; |
| 142 |
|
143 |
|
| 143 |
if (filename == "-") |
144 |
if (filename == "-") |
| 144 |
{ |
145 |
{ |
| 145 |
LOGME ("using event distribution from stdin"); |
146 |
LOGME ("using event distribution from stdin"); |
| 146 |
input = &std::cin; |
147 |
input = &std::cin; |
| 147 |
} |
148 |
} |
| 148 |
else |
149 |
else |
| 149 |
{ |
150 |
{ |
| 150 |
LOGME ("using event distribution from " << filename); |
151 |
LOGME ("using event distribution from " << filename); |
|
Lines 153-167
GetRandomStream (std::string filename)
|
Link Here
|
|---|
|
| 153 |
|
154 |
|
| 154 |
double value; |
155 |
double value; |
| 155 |
std::vector<double> nsValues; |
156 |
std::vector<double> nsValues; |
| 156 |
|
157 |
|
| 157 |
while (!input->eof ()) |
158 |
while (!input->eof ()) |
| 158 |
{ |
159 |
{ |
| 159 |
if (*input >> value) |
160 |
if (*input >> value) |
| 160 |
{ |
161 |
{ |
| 161 |
uint64_t ns = (uint64_t) (value * 1000000000); |
162 |
uint64_t ns = (uint64_t) (value * 1000000000); |
| 162 |
nsValues.push_back (ns); |
163 |
nsValues.push_back (ns); |
| 163 |
} |
164 |
} |
| 164 |
else |
165 |
else |
| 165 |
{ |
166 |
{ |
| 166 |
input->clear (); |
167 |
input->clear (); |
| 167 |
std::string line; |
168 |
std::string line; |
|
Lines 173-179
GetRandomStream (std::string filename)
|
Link Here
|
|---|
|
| 173 |
drv->SetValueArray (&nsValues[0], nsValues.size ()); |
174 |
drv->SetValueArray (&nsValues[0], nsValues.size ()); |
| 174 |
stream = drv; |
175 |
stream = drv; |
| 175 |
} |
176 |
} |
| 176 |
|
177 |
|
| 177 |
return stream; |
178 |
return stream; |
| 178 |
} |
179 |
} |
| 179 |
|
180 |
|
|
Lines 191-197
int main (int argc, char *argv[])
|
Link Here
|
|---|
|
| 191 |
uint32_t total = 1000000; |
192 |
uint32_t total = 1000000; |
| 192 |
uint32_t runs = 1; |
193 |
uint32_t runs = 1; |
| 193 |
std::string filename = ""; |
194 |
std::string filename = ""; |
| 194 |
|
195 |
|
| 195 |
CommandLine cmd; |
196 |
CommandLine cmd; |
| 196 |
cmd.Usage ("Benchmark the simulator scheduler.\n" |
197 |
cmd.Usage ("Benchmark the simulator scheduler.\n" |
| 197 |
"\n" |
198 |
"\n" |
|
Lines 216-224
int main (int argc, char *argv[])
|
Link Here
|
|---|
|
| 216 |
g_fwidth += 6; // 5 extra chars in '2.000002e+07 ': . e+0 _ |
217 |
g_fwidth += 6; // 5 extra chars in '2.000002e+07 ': . e+0 _ |
| 217 |
|
218 |
|
| 218 |
ObjectFactory factory ("ns3::MapScheduler"); |
219 |
ObjectFactory factory ("ns3::MapScheduler"); |
| 219 |
if (schedCal) { factory.SetTypeId ("ns3::CalendarScheduler"); } |
220 |
if (schedCal) |
| 220 |
if (schedHeap) { factory.SetTypeId ("ns3::HeapScheduler"); } |
221 |
{ |
| 221 |
if (schedList) { factory.SetTypeId ("ns3::ListScheduler"); } |
222 |
factory.SetTypeId ("ns3::CalendarScheduler"); |
|
|
223 |
} |
| 224 |
if (schedHeap) |
| 225 |
{ |
| 226 |
factory.SetTypeId ("ns3::HeapScheduler"); |
| 227 |
} |
| 228 |
if (schedList) |
| 229 |
{ |
| 230 |
factory.SetTypeId ("ns3::ListScheduler"); |
| 231 |
} |
| 222 |
Simulator::SetScheduler (factory); |
232 |
Simulator::SetScheduler (factory); |
| 223 |
|
233 |
|
| 224 |
LOGME (std::setprecision (g_fwidth - 6)); |
234 |
LOGME (std::setprecision (g_fwidth - 6)); |
|
Lines 228-234
int main (int argc, char *argv[])
|
Link Here
|
|---|
|
| 228 |
LOGME ("population: " << pop); |
238 |
LOGME ("population: " << pop); |
| 229 |
LOGME ("total events: " << total); |
239 |
LOGME ("total events: " << total); |
| 230 |
LOGME ("runs: " << runs); |
240 |
LOGME ("runs: " << runs); |
| 231 |
|
241 |
|
| 232 |
Bench *bench = new Bench (pop, total); |
242 |
Bench *bench = new Bench (pop, total); |
| 233 |
bench->SetRandomStream (GetRandomStream (filename)); |
243 |
bench->SetRandomStream (GetRandomStream (filename)); |
| 234 |
|
244 |
|
|
Lines 246-260
int main (int argc, char *argv[])
|
Link Here
|
|---|
|
| 246 |
std::left << std::setw (g_fwidth) << "Per (s/ev)" ); |
256 |
std::left << std::setw (g_fwidth) << "Per (s/ev)" ); |
| 247 |
LOG (std::setfill ('-') << |
257 |
LOG (std::setfill ('-') << |
| 248 |
std::right << std::setw (g_fwidth) << " " << |
258 |
std::right << std::setw (g_fwidth) << " " << |
| 249 |
std::right << std::setw (g_fwidth) << " " << |
259 |
std::right << std::setw (g_fwidth) << " " << |
| 250 |
std::right << std::setw (g_fwidth) << " " << |
260 |
std::right << std::setw (g_fwidth) << " " << |
| 251 |
std::right << std::setw (g_fwidth) << " " << |
261 |
std::right << std::setw (g_fwidth) << " " << |
| 252 |
std::right << std::setw (g_fwidth) << " " << |
262 |
std::right << std::setw (g_fwidth) << " " << |
| 253 |
std::right << std::setw (g_fwidth) << " " << |
263 |
std::right << std::setw (g_fwidth) << " " << |
| 254 |
std::right << std::setw (g_fwidth) << " " << |
264 |
std::right << std::setw (g_fwidth) << " " << |
| 255 |
std::setfill (' ') |
265 |
std::setfill (' ') |
| 256 |
); |
266 |
); |
| 257 |
|
267 |
|
| 258 |
// prime |
268 |
// prime |
| 259 |
DEB ("priming"); |
269 |
DEB ("priming"); |
| 260 |
std::cout << std::left << std::setw (g_fwidth) << "(prime)"; |
270 |
std::cout << std::left << std::setw (g_fwidth) << "(prime)"; |
|
Lines 265-277
int main (int argc, char *argv[])
|
Link Here
|
|---|
|
| 265 |
for (uint32_t i = 0; i < runs; i++) |
275 |
for (uint32_t i = 0; i < runs; i++) |
| 266 |
{ |
276 |
{ |
| 267 |
std::cout << std::setw (g_fwidth) << i; |
277 |
std::cout << std::setw (g_fwidth) << i; |
| 268 |
|
278 |
|
| 269 |
bench->RunBench (); |
279 |
bench->RunBench (); |
| 270 |
} |
280 |
} |
| 271 |
|
281 |
|
| 272 |
LOG (""); |
282 |
LOG (""); |
| 273 |
return 0; |
|
|
| 274 |
|
| 275 |
Simulator::Destroy (); |
283 |
Simulator::Destroy (); |
|
|
284 |
delete bench; |
| 276 |
|
285 |
|
|
|
286 |
return 0; |
| 277 |
} |
287 |
} |