Hello,
I am looking at how neko handles simple file io situations, so that one
may bind it to useful C functions like sort and join for data analysis
purposes, but I cannot get reading from stdin fast enough. If I create a
long file 100000 lines or more and parse it line-by-line, it is quite slow:
@@@
file_read_char = $loader.loadprim( "s...@file_read_char", 1 );
file_stdin = $loader.loadprim( "s...@file_stdin", 0 );
readline = function (r)
{
var s = $smake(1);
try
{
s = file_read_char(file_stdin());
} catch e {
return false;
}
if ( s != 10 )
{
var l = $ssize(r), m = $smake(l+1);
$sblit(m,0,r,0,l);
$sset(m,l,s);
return readline(m);
} else {
return r;
}
}
while ((line = readline($smake(0))) != false)
// ...
@@@
Going through the file took 0.8 seconds, whereas perl took 0.06 seconds
Is there a better way of reading from stdin ?
- Niel
--
Neko : One VM to run them all
(http://nekovm.org)