jacobian

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit ffb5d096f474e9931033b74dd12a9eabb9e687bb
parent f8f9b481a76ff638cf082a41db6e02465ce7c5ef
Author: David Freifeld <freifeld.david@gmail.com>
Date:   Wed, 23 Sep 2020 09:58:14 -0700

Testing use of fcntl with RDADVISE

Diffstat:
Msrc/experimental/fileread.cpp | 53++++++++++++++++++++++++++++++++++++++++++-----------
1 file changed, 42 insertions(+), 11 deletions(-)

diff --git a/src/experimental/fileread.cpp b/src/experimental/fileread.cpp @@ -117,13 +117,44 @@ float newer() exit(1); } if (!bytes_read) break; - for(char *p = buf; p < buf+BUFFER_SIZE;) { - for (int i=0; i<5; ++i) { - tmp = *((float*)p); - p += sizeof(float); - } - ++lines; + // for(char *p = buf; p < buf+BUFFER_SIZE;) { + // for (int i=0; i<5; ++i) { + // tmp = *((float*)p); + // p += sizeof(float); + // } + // ++lines; + // } + } + return tmp; +} + +float newest() +{ + static const auto BUFFER_SIZE = 600*1024; + int fd = open("../../data_banknote_authentication.bin", O_RDONLY | O_NONBLOCK); + fcntl(fd, F_RDADVISE); + uintmax_t maxlines = 1003222; + if(fd == -1) { + printf("Cannot open file."); + exit(1); + } + char buf[BUFFER_SIZE]; + uintmax_t lines = 0; + float tmp; + while(size_t bytes_read = read(fd, buf, BUFFER_SIZE)) + { + if(bytes_read == (size_t)-1) { + printf("bytes_read == (size_t)-1\n"); + exit(1); } + if (!bytes_read) break; + // for(char *p = buf; p < buf+BUFFER_SIZE;) { + // for (int i=0; i<5; ++i) { + // tmp = *((float*)p); + // p += sizeof(float); + // } + // ++lines; + // } } return tmp; } @@ -132,19 +163,19 @@ int main () { int epochs = 1; float tmp; auto start = std::chrono::high_resolution_clock::now(); - prep(); + //prep(); auto prep_end = std::chrono::high_resolution_clock::now(); for (int i = 0; i < epochs; i++) { - tmp = newer(); + tmp = newest(); } auto end = std::chrono::high_resolution_clock::now(); double time = std::chrono::duration_cast<std::chrono::nanoseconds>(end - prep_end + prep_end-start).count() / pow(10,9); double runtime = std::chrono::duration_cast<std::chrono::nanoseconds>(end - prep_end).count() / pow(10,9); float ftmp; auto f_start = std::chrono::high_resolution_clock::now(); - // for (int i = 0; i < epochs; i++) { - // ftmp = current(); - // } + for (int i = 0; i < epochs; i++) { + ftmp = newer(); + } auto f_end = std::chrono::high_resolution_clock::now(); // if (flines == lines) std::cout << "Linecount is valid!" << "\n"; // else std::cout << "WARN: INVALID LINECOUNT " << lines << " vs. " << flines << "\n";