MCPcopy Create free account
hub / github.com/PlatformLab/NanoLog / ifstreamReadHelper

Function ifstreamReadHelper

runtime/Perf.cc:172–196  ·  view source on GitHub ↗

* Reads a number of bytes from an ifstream repeatedly and times it * * \param readSize * Number of bytes to read at once * * \return total time taken to read the readSize in seconds */

Source from the content-addressed store, hash-verified

170 * \return total time taken to read the readSize in seconds
171 */
172double ifstreamReadHelper(int readSize) {
173 int dataLen = 1000000;
174 char *backing_buffer = static_cast<char*>(malloc(dataLen));
175
176 std::ofstream oFile;
177 oFile.open("/tmp/testLog.dat");
178 oFile.write(backing_buffer, dataLen);
179 oFile.close();
180
181 // Read it back
182 std::ifstream iFile;
183 iFile.open("/tmp/testLog.dat");
184
185 uint64_t start = Cycles::rdtsc();
186 for (int i = 0; i < dataLen/readSize; ++i) {
187 iFile.read(backing_buffer, readSize);
188 }
189 uint64_t stop = Cycles::rdtsc();
190
191 discard(backing_buffer);
192 std::remove("/tmp/testLog.dat");
193 free(backing_buffer);
194
195 return Cycles::toSeconds(stop - start)/(dataLen/readSize);
196}
197
198double ifstreamRead1() {
199 return ifstreamReadHelper(1);

Callers 3

ifstreamRead1Function · 0.85
ifstreamRead10Function · 0.85
ifstreamRead100Function · 0.85

Calls 3

rdtscFunction · 0.85
openMethod · 0.80
discardFunction · 0.70

Tested by

no test coverage detected