> function testparse()
> parse("4.123456789")
> end
Try:
function testparse()
parse(Float64, "4.123456789")
end
I get 100x speedup.
> @time testparse()
> @time for i=1:1
> testparse()
> end
> Running this on the same machine takes about 0.65 seconds. I get similar
> results
Excellent. I get a more than 100x speedup to. Then the question is, how
to make a good utility function, which reads numbers from a line of input
with the types specified for speed.
Here is something that seems to work correctly:
function getline(src,a,b...)
ss = split(readline(src))
Adrian--thanks!
I have a followup: parse seems about 100 times slower than the equivalent
C++ code. I would have hoped for only a
factor of two or so. Here is a C++ code fragment:
for(int i = 1; i <= 100; i++)
{
std::string s("4.123456789");
std::istringstream iss(s);
double d;
iss >>
The essential part first:
julia> a,b,c,d=map(parse,split("9 2 2 1.3\n"))
4-element Array{Real,1}:
9
2
2
1.3
but see what you actually get back...
julia> typeof(a)
Int64
julia> typeof(d)
Float64
That's Julia's type inferencing at play. And functional abilities (map,
parse). See the manual on
Say I have a data file in plain text, which starts with some lines that
describe matrix sizes, etc, for the data that follows. For example, the
first line might be
9 2 2 1.3
To read this file, in C I would use something like this call to scanf:
scanf("%d%d%d%lf");
How do I do this in