1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
3 * Copyright (c) 2006 INRIA
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
21 #include "ns3/simulator-module.h"
22 #include "ns3/core-module.h"
37 void ReadDistribution (std::istream &istream);
38 void SetTotal (uint32_t total);
42 std::vector<uint64_t> m_distribution;
43 std::vector<uint64_t>::const_iterator m_current;
54 Bench::SetTotal (uint32_t total)
60 Bench::ReadDistribution (std::istream &input)
67 uint64_t ns = (uint64_t) (data * 1000000000);
68 m_distribution.push_back (ns);
80 Bench::RunBench (void)
82 SystemWallClockMs time;
85 for (std::vector<uint64_t>::const_iterator i = m_distribution.begin ();
86 i != m_distribution.end (); i++)
88 Simulator::Schedule (NanoSeconds (*i), &Bench::Cb, this);
93 m_current = m_distribution.begin ();
101 "init n=" << m_distribution.size () << ", time=" << init << "s" << std::endl <<
102 "simu n=" << m_n << ", time=" <<simu << "s" << std::endl <<
103 "init " << ((double)m_distribution.size ()) / init << " insert/s, avg insert=" <<
104 init / ((double)m_distribution.size ())<< "s" << std::endl <<
105 "simu " << ((double)m_n) / simu<< " hold/s, avg hold=" <<
106 simu / ((double)m_n) << "s" << std::endl
117 if (m_current == m_distribution.end ())
119 m_current = m_distribution.begin ();
123 std::cerr << "event at " << Simulator::Now ().GetSeconds () << "s" << std::endl;
125 Simulator::Schedule (NanoSeconds (*m_current), &Bench::Cb, this);
133 std::cout << "bench-simulator filename [options]"<<std::endl;
134 std::cout << " filename: a string which identifies the input distribution. \"-\" represents stdin." << std::endl;
135 std::cout << " Options:"<<std::endl;
136 std::cout << " --list: use std::list scheduler"<<std::endl;
137 std::cout << " --map: use std::map cheduler"<<std::endl;
138 std::cout << " --heap: use Binary Heap scheduler"<<std::endl;
139 std::cout << " --debug: enable some debugging"<<std::endl;
142 int main (int argc, char *argv[])
144 char const *filename = argv[1];
147 uint32_t total = 20000;
155 if (strcmp (filename, "-") == 0)
161 input = new std::ifstream (filename);
165 ObjectFactory factory;
166 if (strcmp ("--list", argv[0]) == 0)
168 factory.SetTypeId ("ns3::ListScheduler");
169 Simulator::SetScheduler (factory);
171 else if (strcmp ("--heap", argv[0]) == 0)
173 factory.SetTypeId ("ns3::HeapScheduler");
174 Simulator::SetScheduler (factory);
176 else if (strcmp ("--map", argv[0]) == 0)
178 factory.SetTypeId ("ns3::HeapScheduler");
179 Simulator::SetScheduler (factory);
181 else if (strcmp ("--calendar", argv[0]) == 0)
183 factory.SetTypeId ("ns3::CalendarScheduler");
184 Simulator::SetScheduler (factory);
186 else if (strcmp ("--debug", argv[0]) == 0)
190 else if (strncmp ("--total=", argv[0], strlen("--total=")) == 0)
192 total = atoi (argv[0]+strlen ("--total="));
194 else if (strncmp ("--n=", argv[0], strlen("--n=")) == 0)
196 n = atoi (argv[0]+strlen ("--n="));
202 Bench *bench = new Bench ();
203 bench->ReadDistribution (*input);
204 bench->SetTotal (total);
205 for (uint32_t i = 0; i < n; i++)