# Compare array with threshold - what way will be faster

Discussion created by Raistmer on Apr 22, 2010
Latest reply on Apr 22, 2010 by Raistmer
I need to check if some array has value that exceeds some threshold or not.
Exceeding threshold can be considered as rare event, most values will be under threshold.
What way should be faster?
1) many if operations (remember, exceeding threshold is rare event, not much divergent branching expected here)
2) using fmax function and then compare max value for array with treshold.

I listed examples of both approaches implementation.
Or, maybe, something else will be even better?

`1) many if instructions: if(was_pulse.x==0){//R: if pulse already detected no need to check other elements, it will be done on CPU anyway for(int i=0;i<128;i++){if ( (d[i].x>t.x)||(d[i].y>t.x)||(d[i].z>t.x)||(d[i].w>t.x) ){was_pulse.x=1;break;}} } 2) using fmax: if(was_pulse.x==0){//R: if pulse already detected no need to check other elements, it will be done on CPU anyway pmax=fmax(d[0],d[1]); for(int i=2;i<128;i++){pmax=fmax(pmax,d[i]);} pmax.xy=fmax(pmax.xy,pmax.zw);pmax.x=fmax(pmax.x,pmax.y); if(pmax.x>t.x){was_pulse.x=1;} }`