My app will be running on an iPad with A7. I pass in 3 JSON arrays and right now do some simple filtering, in the future the operation will be much more complicated. I realize the if
statement is slowing down the process, but how can I avoid it? Is there a way to have this loop on one CPU and run the GUI on the other CPU (assign affinity)?
class func filterPhenotypeByPvalues(
phenotypeJSON:[String],
SNPJSON:[String],
dataJSON:[Float],
limit:Float) -> ([Float],[String],[String])
{
let dbg:Bool = true
var PvalueFiltered:[Float] = []
var PhenotypeFiltered:[String] = []
var SNPFiltered:[String] = []
//initialize arrays with value
//[Float](count: data.count, repeatedValue: 0.0)
var i:Int = 0
let startTime = CFAbsoluteTimeGetCurrent()
for (i = 0; i < dataJSON.count; i++) {
if dataJSON[i] <= limit {
PvalueFiltered.append(-log10(dataJSON[i]))
PhenotypeFiltered.append(phenotypeJSON[i])
SNPFiltered.append(SNPJSON[i])
}
}
let timeElapsed = CFAbsoluteTimeGetCurrent() - startTime
if(dbg){println("Time elapsed filterPhenotypeByPvalues: \(timeElapsed) s")}
return (PvalueFiltered,PhenotypeFiltered,SNPFiltered)
}
A very small sample of the JSON data file:
{
"data": [
["rs6855911","Negative control - flare length",0.0000000002],
["rs6855911","BMD of intertrochanter region - gm/cm sq",0.0000000007],
["rs1501908","BMD of intertrochanter region - gm/cm sq",0.000000001]
]
}
Screenshot of timing profile: