25 #include "ns3/core-module.h"
40 PerfFile (FILE *
file, uint32_t n,
const char *buffer, uint32_t size)
42 for (uint32_t i = 0; i < n; ++i)
44 if (std::fwrite (buffer, 1, size,
file) != size)
62 PerfStream (std::ostream &stream, uint32_t n,
const char *buffer, uint32_t size)
64 for (uint32_t i = 0; i < n; ++i)
66 stream.write (buffer, size);
71 main (
int argc,
char *argv[])
75 bool doStream =
false;
79 cmd.AddValue (
"n",
"How many times to write (defaults to 100000", n);
80 cmd.AddValue (
"iter",
"How many times to run the test looking for a min (defaults to 50)", iter);
81 cmd.AddValue (
"doStream",
"Run the C++ I/O benchmark otherwise the C I/O ", doStream);
82 cmd.AddValue (
"binmode",
"Select binary mode for the C++ I/O benchmark (defaults to true)", binmode);
83 cmd.Parse (argc, argv);
85 auto minResultNs = std::chrono::duration_cast<std::chrono::nanoseconds> (
97 for (uint32_t i = 0; i < iter; ++i)
102 stream.open (
"streamtest", std::ios_base::binary | std::ios_base::out);
106 stream.open (
"streamtest", std::ios_base::out);
109 auto start = std::chrono::steady_clock::now ();
111 auto end = std::chrono::steady_clock::now ();
112 auto resultNs = std::chrono::duration_cast<std::chrono::nanoseconds> (end -
start);
113 resultNs =
std::min (resultNs, minResultNs);
115 std::cout <<
"."; std::cout.flush ();
118 std::cout << std::endl;
127 for (uint32_t i = 0; i < iter; ++i)
129 FILE *
file = fopen (
"filetest",
"w");
131 auto start = std::chrono::steady_clock::now ();
133 auto end = std::chrono::steady_clock::now ();
134 auto resultNs = std::chrono::duration_cast<std::chrono::nanoseconds> (end -
start);
135 resultNs =
std::min (resultNs, minResultNs);
138 std::cout <<
"."; std::cout.flush ();
140 std::cout << std::endl;
143 std::cout << argv[0] <<
": " << minResultNs.count () <<
"ns" << std::endl;
Parse command-line arguments.
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
void PerfFile(FILE *file, uint32_t n, const char *buffer, uint32_t size)
Check the performance of writing to file.
void PerfStream(std::ostream &stream, uint32_t n, const char *buffer, uint32_t size)
Check the performance of writing to an output stream.
Every class exported by the ns3 library is enclosed in the ns3 namespace.