26 #include "ns3/core-module.h"
27 #include "ns3/abort.h"
39 gettimeofday (&tv, NULL);
46 PerfFile (FILE *file, uint32_t n,
const char *buffer, uint32_t size)
48 for (uint32_t i = 0; i < n; ++i)
50 if (std::fwrite (buffer, 1, size, file) != size)
58 PerfStream (ostream &stream, uint32_t n,
const char *buffer, uint32_t size)
61 for (uint32_t i = 0; i < n; ++i)
63 stream.write (buffer, size);
68 main (
int argc,
char *argv[])
72 bool doStream =
false;
77 cmd.
AddValue (
"n",
"How many times to write (defaults to 100000", n);
78 cmd.
AddValue (
"iter",
"How many times to run the test looking for a min (defaults to 50)", iter);
79 cmd.
AddValue (
"doStream",
"Run the C++ I/O benchmark otherwise the C I/O ", doStream);
80 cmd.
AddValue (
"binmode",
"Select binary mode for the C++ I/O benchmark (defaults to true)", binmode);
81 cmd.
Parse (argc, argv);
83 uint64_t result = std::numeric_limits<uint64_t>::max ();
94 for (uint32_t i = 0; i < iter; ++i)
99 stream.open (
"streamtest", std::ios_base::binary | std::ios_base::out);
103 stream.open (
"streamtest", std::ios_base::out);
109 result = min (result, et);
111 std::cout <<
"."; std::cout.flush ();
122 for (uint32_t i = 0; i < iter; ++i)
124 FILE *file = fopen (
"filetest",
"w");
129 result = std::min (result, et);
132 std::cout <<
"."; std::cout.flush ();
134 std::cout << std::endl;
136 std::cout << argv[0] <<
": " << result <<
"ns" << std::endl;
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
uint64_t GetRealtimeInNs(void)
void PerfFile(FILE *file, uint32_t n, const char *buffer, uint32_t size)
static const uint64_t NS_PER_SEC
Parse command-line arguments.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static const uint64_t US_PER_NS
static const uint64_t US_PER_SEC
void AddValue(const std::string &name, const std::string &help, T &value)
Add a program argument, assigning to POD.
void Parse(int argc, char *argv[])
Parse the program arguments.
void PerfStream(ostream &stream, uint32_t n, const char *buffer, uint32_t size)