Runs about 3275 msecs on my machine, so the math seems to have an impact. Here is the benchmark script, just rename the function as required. Don't think the order of functions has an impact:

code:
break on

$start = @TICKS

for $i = 0 to 10000
$c = fadeToBlack2(&FFAADD,&DD)
next

?"elapsed=" @TICKS-$start

exit 1

function FadeToBlack($c, $)

dim $B, $G, $R

$b = $c / 65536
$g = ($c & &FF00) / 256
$r = $c & &FF

if $B>$ $B=$ endif
if $G>$ $G=$ endif
if $R>$ $R=$ endif

$FadeToBlack = $B*65536+$G*256+$R

endfunction

function FadeToBlack2($c, $)

$FadeToBlack2 =
iif($c/65536>$, $, $c/65536) * 65536 +
iif(($c & 65280) / 256>$, $, ($c & 65280) / 256) * 256 +
iif($c & 255>$, $, $c & 255)

endfunction