Hi,

Just profiled these with a variety of inputs and the first is around 3 times as 
fast as the second.

I added a null check to stop the RTE, if the null check is not needed it can be 
removed from both.

public function test(str:String):Number {
    var pixels:Number = NaN;
    if (str !== null && str.indexOf('%') === -1)
        pixels = parseFloat(str);

    return pixels;  
}

public function test2(str:String):Number {
    var pixels:Number;
    if (str !== null && str.indexOf('%') != -1)
        pixels = NaN;
    else if (str !== null && str.length == 0)
        pixels = NaN;
    else
        pixels = parseFloat(str);

    return pixels;
}

Thanks,
Justin

Reply via email to