* 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 */
| 216 | * \return total time taken to read the readSize in seconds |
| 217 | */ |
| 218 | double 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 | |
| 249 | double fread1() { |
| 250 | return freadHelper(1); |