26 #include "ns3/core-module.h"
27 #include "ns3/network-module.h"
28 #include "ns3/abort.h"
40 gettimeofday (&tv, NULL);
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);
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");
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;
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.
static const uint64_t US_PER_NS
static const uint64_t US_PER_SEC
#define NS_ABORT_MSG(msg)
Abnormal program termination.
void AddValue(const std::string &name, const std::string &help, T &value)
Add a program argument, assigning to POD.
int main(int argc, char *argv[])
void Parse(int argc, char *argv[])
Parse the program arguments.
void PerfStream(ostream &stream, uint32_t n, const char *buffer, uint32_t size)