jacobian

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

commit bb352786c636e30323827b9035f922387e2cfb50
parent 802e25c4bb1f0aa912b752e7b2de2fe4bfd72d50
Author: David Freifeld <freifeld.david@gmail.com>
Date:   Mon, 21 Sep 2020 22:29:48 -0700

Fixed benchmark

Diffstat:
Msrc/experimental/fileread.cpp | 12+++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/src/experimental/fileread.cpp b/src/experimental/fileread.cpp @@ -25,8 +25,6 @@ // for (int i = 0; // } -char newline = '\n'; - // Courtesy of github.com/exr0n typedef float val_t; inline float scan(char **p) @@ -74,7 +72,7 @@ float current() void prep() { - int wptr = open("../../data_banknote_authentication.bin", O_WRONLY | O_NONBLOCK); + FILE* wptr = fopen("../../data_banknote_authentication.bin", "wb"); static const auto BUFFER_SIZE = 16*1024; int fd = open("../../data_banknote_authentication.txt", O_RDONLY | O_NONBLOCK); if(fd == -1) { @@ -93,9 +91,10 @@ void prep() if (bound - p < 0) break; // Stop. for (int i=0; i<5; ++i) { tmp = scan(&p); - write(wptr, (void*)&tmp, sizeof(float)); + fwrite((void*)&tmp, sizeof(float), 1, wptr); } p = bound + 1; + putc('\n', wptr); } } } @@ -118,11 +117,14 @@ float newer() return 1; } if (!bytes_read) break; - for(char *p = buf; p < buf+BUFFER_SIZE;) { + for(char *p = buf;;) { + char* bound = (char*) memchr(p, '\n', (buf + bytes_read) - p); + if (bound - p < 0) break; // Stop. for (int i=0; i<5; ++i) { tmp = *((float*)p); p += sizeof(float); } + p = bound + 1; ++lines; } }