* 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 */
| 170 | * \return total time taken to read the readSize in seconds |
| 171 | */ |
| 172 | double 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 | |
| 198 | double ifstreamRead1() { |
| 199 | return ifstreamReadHelper(1); |
no test coverage detected