Working with big files, I have to convert some numbers that are in string format into real MMA numbers. I know that I can use ToExpression
but it's slow when compared to another forms.
For instance, for Integer case we can compare:
dataInt = ToString /@ RandomInteger[1000, {10^5}];
d1 = FromDigits /@ dataInt; // AbsoluteTiming
d2 = ToExpression /@ dataInt; // AbsoluteTiming
{0.050298, Null}
{0.475669, Null}
It's almost 10 times faster to use FromDigits
. The question is, how can I make a equivalent for Real cases? Like:
dataReal = ToString /@ RandomReal[1000, {10^5}];
d1 = someFunction/@dataReal;//AbsoluteTiming
d2 = ToExpression/@dataReal;//AbsoluteTiming
I haven't found some Mathematica function to someFunction
. I miss one way to force ToExpression
to interpret the string in some specific way.
Comments
Post a Comment