26 #include "ns3/core-module.h"
27 #include "ns3/network-module.h"
28 #include "ns3/abort.h"
32 static const uint64_t US_PER_NS = (uint64_t)1000;
33 static const uint64_t US_PER_SEC = (uint64_t)1000000;
34 static const uint64_t NS_PER_SEC = (uint64_t)1000000000;
37 GetRealtimeInNs (
void)
40 gettimeofday (&tv, NULL);
42 uint64_t nsResult = tv.tv_sec * NS_PER_SEC + tv.tv_usec * US_PER_NS;
47 PerfFile (FILE *file, uint32_t n,
const char *buffer, uint32_t size)
49 for (uint32_t i = 0; i < n; ++i)
51 if (std::fwrite (buffer, 1, size, file) != size)
59 PerfStream (ostream &stream, uint32_t n,
const char *buffer, uint32_t size)
62 for (uint32_t i = 0; i < n; ++i)
64 stream.write (buffer, size);
69 main (
int argc,
char *argv[])
73 bool doStream =
false;
78 cmd.
AddValue (
"n",
"How many times to write (defaults to 100000", n);
79 cmd.
AddValue (
"iter",
"How many times to run the test looking for a min (defaults to 50)", iter);
80 cmd.
AddValue (
"doStream",
"Run the C++ I/O benchmark otherwise the C I/O ", doStream);
81 cmd.
AddValue (
"binmode",
"Select binary mode for the C++ I/O benchmark (defaults to true)", binmode);
82 cmd.
Parse (argc, argv);
84 uint64_t result = std::numeric_limits<uint64_t>::max ();
95 for (uint32_t i = 0; i < iter; ++i)
100 stream.open (
"streamtest", std::ios_base::binary | std::ios_base::out);
104 stream.open (
"streamtest", std::ios_base::out);
107 uint64_t start = GetRealtimeInNs ();
108 PerfStream (stream, n, buffer, 1024);
109 uint64_t et = GetRealtimeInNs () - start;
110 result = min (result, et);
112 std::cout <<
"."; std::cout.flush ();
123 for (uint32_t i = 0; i < iter; ++i)
125 FILE *file = fopen (
"filetest",
"w");
127 uint64_t start = GetRealtimeInNs ();
128 PerfFile (file, n, buffer, 1024);
129 uint64_t et = GetRealtimeInNs () - start;
130 result = std::min (result, et);
133 std::cout <<
"."; std::cout.flush ();
135 std::cout << std::endl;
137 std::cout << argv[0] <<
": " << result <<
"ns" << std::endl;
parse command-line argumentsInstances of this class can be used to parse command-line arguments: user...
#define NS_ABORT_MSG(msg)
Abnormal program termination.
void AddValue(const std::string &name, const std::string &help, T &value)
void Parse(int argc, char *argv[]) const