16 #include "ns3/core-module.h"
37 PerfFile(FILE*
file, uint32_t n,
const char* buffer, uint32_t size)
39 for (uint32_t i = 0; i < n; ++i)
41 if (std::fwrite(buffer, 1, size,
file) != size)
59 PerfStream(std::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;
76 cmd.AddValue(
"n",
"How many times to write (defaults to 100000", n);
77 cmd.AddValue(
"iter",
"How many times to run the test looking for a min (defaults to 50)", iter);
78 cmd.AddValue(
"doStream",
"Run the C++ I/O benchmark otherwise the C I/O ", doStream);
79 cmd.AddValue(
"binmode",
80 "Select binary mode for the C++ I/O benchmark (defaults to true)",
82 cmd.Parse(argc, argv);
96 for (uint32_t i = 0; i < iter; ++i)
101 stream.open(
"streamtest", std::ios_base::binary | std::ios_base::out);
105 stream.open(
"streamtest", std::ios_base::out);
108 auto start = std::chrono::steady_clock::now();
110 auto end = std::chrono::steady_clock::now();
111 auto resultNs = std::chrono::duration_cast<std::chrono::nanoseconds>(end -
start);
112 resultNs =
std::min(resultNs, minResultNs);
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);
141 std::cout << std::endl;
144 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.