Last active
August 29, 2015 14:19
-
-
Save cajlarsson/ab33f66d40da17b89409 to your computer and use it in GitHub Desktop.
librcd split
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "rcd.h" | |
#import "rio.h" | |
#pragma librcd | |
void rcd_main(list(fstr_t)* main_args, list(fstr_t)* main_env) { | |
rio_t* in = rio_stdin(); | |
volatile size_t lines = 0; | |
fstr_t line_tail; | |
uint128_t before = rio_epoch_ns_now(); | |
fstr_t buffer = fss(fstr_alloc_buffer(PAGE_SIZE*1000)); | |
volatile size_t words = 0; | |
try { | |
for(;;) { | |
line_tail = rio_read_to_separator(in, "\n", buffer); | |
lines++; | |
fstr_t word; | |
while (fstr_iterate(&line_tail, " ", &word)) | |
if (word.len > 0) | |
words++; | |
} | |
} catch(exception_io, e); | |
uint128_t after = rio_epoch_ns_now(); | |
rio_debug(concs("saw ", lines, " lines and ", words , " words in ", after - before, "ns.\n")); | |
lwt_exit(0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment