jacobian

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

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

Binary gives lots of speed

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

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