objective c - Performance issue when converting many floats to NSNumbers -
in application, i'm receiving csv
file contains 30,000 objects , each object there 24 values (a total of 720,000 values).
format this:
object1,value1,value2,...,value24
object2,value1,value2,...,value24
...
objectn,value1,value2,...,value24
when parse file, convert each row in nsarray
of nsstring
. next following each value of array:
- convert
nsstring
float
using- (float)floatvalue
- convert
float
nsnumber
- store
nsnumber
innsmutablearray
this process takes several seconds , instruments time profiler
i'm spending 3.5 s in step 2 & 3 720,000 values.
how can proceed avoid nsnumber
translation? can use c style array, []
? or cfmutablearrayref
? if helps, know there 24 values each object.
thanks help,
sébastien.
personally i'd use c-style array. if want process data row row, have object representing each row, this:
@interface row : nsobject { float values[24]; } @end
then create row instance each row, set 24 values directly, , add instance nsmutablearray.
row *row = [[[row alloc] init] autorelease]; // here's read in data row , save 24 values row.values[0] = ... ... row.values[23] = ... // , here add row instance nsmutablearray [rows addobject:row];
otherwise, if know front you're going expecting 30,000 rows preallocate 30,000 x 24 array of floats.
float *rows = calloc(30000*24, sizeof(float)); (int = 0; < 30000; i++) { float *values = rows[24*i]; // here's read in data row , save 24 values values[0] = ... ... values[23] = ... }
just don't forget you'll need free memory calloc
when you're done it.
Comments
Post a Comment