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

Function freadHelper

runtime/Perf.cc:218–247  ·  view source on GitHub ↗

* Reads a number of bytes from an fread 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

216 * \return total time taken to read the readSize in seconds
217 */
218double freadHelper(int readSize) {
219 int dataLen = 1000000;
220 char *backing_buffer = static_cast<char*>(malloc(dataLen));
221
222 std::ofstream oFile;
223 oFile.open("/tmp/testLog.dat");
224 oFile.write(backing_buffer, dataLen);
225 oFile.close();
226
227 // Read it back
228 FILE *fd = fopen ("/tmp/testLog.dat", "r");
229 if (!fd) {
230 printf("Error: fread test could not open temp file/tmp/testLog.dat\r\n");
231 exit(1);
232 }
233
234 uint64_t start = Cycles::rdtsc();
235 for (int i = 0; i < dataLen/readSize; ++i) {
236 fread(backing_buffer, 1, readSize, fd);
237 }
238 uint64_t stop = Cycles::rdtsc();
239
240 discard(backing_buffer);
241 free(backing_buffer);
242
243 fclose(fd);
244 std::remove("/tmp/testLog.dat");
245
246 return Cycles::toSeconds(stop - start)/(dataLen/readSize);
247}
248
249double fread1() {
250 return freadHelper(1);

Callers 3

fread1Function · 0.85
fread10Function · 0.85
fread100Function · 0.85

Calls 3

rdtscFunction · 0.85
openMethod · 0.80
discardFunction · 0.70

Tested by

no test coverage detected