#106509 - 2003-11-03 04:38 PM
Re: Mini-putt for a slow day on korg ...
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
code:
function FadeToBlack($color, $level)
Dim $B, $G, $R $B=$color/65536 $G=($color mod 65536)/256 $R=$color-($B*65536)-($G*256)
$B = IIF($B>$level, $level, $B) $G = IIF($G>$level, $level, $G) $R = IIF($R>$level, $level, $R)
;by matching level these checks are no longer required. ;$B = IIF($B<0, 0, $B) ;$G = IIF($G<0, 0, $G) ;$R = IIF($R<0, 0, $R)
$FadeToBlack = ($B*65536)+($G*256)+$R
endfunction
[ 03. November 2003, 16:41: Message edited by: Howard Bullock ]
|
|
Top
|
|
|
|
#106511 - 2003-11-03 04:54 PM
Re: Mini-putt for a slow day on korg ...
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Shawn did you catch the edit above?
|
|
Top
|
|
|
|
#106513 - 2003-11-03 05:04 PM
Re: Mini-putt for a slow day on korg ...
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Like this? code:
function FadeToBlack($c, $)
Dim $B, $G, $R $B=$c/65536 $G=($c mod 65536)/256 $R=$c-($B*65536)-($G*256)
$B = IIF($B>$, $, $B) $G = IIF($G>$, $, $G) $R = IIF($R>$, $, $R)
$FadeToBlack = $B*65536+$G*256+$R
endfunction
[ 03. November 2003, 17:06: Message edited by: Howard Bullock ]
|
|
Top
|
|
|
|
#106514 - 2003-11-03 05:11 PM
Re: Mini-putt for a slow day on korg ...
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Shawn, I would think that this would be faster. The IIF has to rest the value of the color variable even if it did not need to change it. code:
function FadeToBlack($c, $)
Dim $B, $G, $R $B=$c/65536 $G=($c mod 65536)/256 $R=$c-($B*65536)-($G*256)
if $B>$ $B=$ endif if $G>$ $G=$ endif if $R>$ $R=$ endif $FadeToBlack = $B*65536+$G*256+$R
endfunction
|
|
Top
|
|
|
|
#106515 - 2003-11-03 05:45 PM
Re: Mini-putt for a slow day on korg ...
|
Shawn
Administrator
   
Registered: 1999-08-13
Posts: 8611
|
Howard, just working on my short game here. Wondering if this might be shorter/faster ...
code:
$r = $c & &FF $g = ($c & &FF00) / 256 $b = ($c & &FF0000) / 65536
plus, I concatenated your IIF's (which I like) into a big long expression:
code:
$FadeToBlack = IIF($B>$, $, $B) * 65536 + IIF($G>$, $, $G) * 256 + IIF($R>$, $, $R)
-Shawn [ 03. November 2003, 17:48: Message edited by: Shawn ]
|
|
Top
|
|
|
|
#106516 - 2003-11-03 06:16 PM
Re: Mini-putt for a slow day on korg ...
|
Shawn
Administrator
   
Registered: 1999-08-13
Posts: 8611
|
hmmm, combining both strategies yields:
code:
function FadeToBlack($c, $)
dim $b, $g, $r
$b = $c / 65536 $g = ($c & &FF00) / 256 $r = $c & &FF
$FadeToBlack = iif($b>$, $, $b) * 65536 + iif($g>$, $, $g) * 256 + IIF($r>$, $, $r)
endfunction
|
|
Top
|
|
|
|
#106517 - 2003-11-03 06:29 PM
Re: Mini-putt for a slow day on korg ...
|
Shawn
Administrator
   
Registered: 1999-08-13
Posts: 8611
|
Think this is actually four chars shorter. Even with the redundancy ...
code:
function FadeToBlack($c, $)
$FadeToBlack = iif($c/65536>$, $, $c/65536) * 65536 + iif(($c & 65280) / 256>$, $, ($c & 65280) / 256) * 256 + iif($c & 255>$, $, $c & 255)
endfunction
[ 03. November 2003, 18:29: Message edited by: Shawn ]
|
|
Top
|
|
|
|
#106518 - 2003-11-03 06:36 PM
Re: Mini-putt for a slow day on korg ...
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
But is your goal the least characters used or the most efficient code with he fastest execution?
Do you have any benchmarks for each version? [ 03. November 2003, 18:45: Message edited by: Howard Bullock ]
|
|
Top
|
|
|
|
#106521 - 2003-11-03 06:50 PM
Re: Mini-putt for a slow day on korg ...
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Yes, what is that result???
|
|
Top
|
|
|
|
#106523 - 2003-11-03 06:56 PM
Re: Mini-putt for a slow day on korg ...
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Crap!
I still think the If...Endif should be faster than IIF.
Keep the If..Endif's and toss the "mod" operator in favor of the "&" bitwise operator. The slowness is probably in the additional math I do.
|
|
Top
|
|
|
|
#106524 - 2003-11-03 06:59 PM
Re: Mini-putt for a slow day on korg ...
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
code:
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
|
|
Top
|
|
|
|
#106525 - 2003-11-03 07:02 PM
Re: Mini-putt for a slow day on korg ...
|
Shawn
Administrator
   
Registered: 1999-08-13
Posts: 8611
|
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
|
|
Top
|
|
|
|
#106526 - 2003-11-03 07:25 PM
Re: Mini-putt for a slow day on korg ...
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Shawn, after some experimentation. I have concluded that the high overhead operation is the instantiation of variables. Your FadeToBlack2 avoids the creation of variables as much as seems possible. The additional calculations appear to add less burden to the process than the creation of variables. Good job optimizing. [ 03. November 2003, 19:28: Message edited by: Howard Bullock ]
|
|
Top
|
|
|
|
Moderator: Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 601 anonymous users online.
|
|
|