Kacper Gutowski wrote:
There's another reason: reading by characters can not be fast.
Regardless the programming language, block I/O should be always preferred.
This should be faster but of course in some cases
it could not be used since it reads some data ahead.
Yes, it's a nice script, when I fiddle with the block parameter, I get a
respectable speed increase. thanks for the idea.. though I still find
neko i/o not so impressive :-|
- Niel
var file_stdin = $loader.loadprim("s...@file_stdin", 0);
var file_read = $loader.loadprim("s...@file_read", 4);
readline = {
var in = file_stdin();
var block = 1024;
var eol = "\n";
var ell = $ssize(eol);
var s = "";
function() {
var e, r;
try {
while ($ssize(s)<1 || (e = $sfind(s, 0, eol)) == null) {
var b = $smake(block);
var l = file_read(in, b, 0, block);
s ++= $ssub(b, 0, l);
}
r = $ssub(s, 0, e);
s = $ssub(s, e+ell, $ssize(s)-e-ell);
}
catch _ if $ssize(s) > 0 { r = s; s = "" }
return r;
}
};
while ((line = readline()) != null) _
Works faster for me.
--
Neko : One VM to run them all
(http://nekovm.org)