Quick Tip: uint To 6 Digit RGB Hex

Shortest possible, simple / no looping method of getting hex string from color is:

var color:uint = 0x00ff00;
var hex:String = color.toString(16);

trace("00000".substr(0, 6 - hex.length) + hex);
// output 00ff00

trace("#00000".substr(0, 7 - hex.length) + hex);
// output #00ff00

ActionScript 3 Performance Testing

Have you ever been curious about performance (benchmark) tests in ActionScript 3? Here are some results gathered from gskinner blog.

Performance testing on loops (read more).

method............................................................. ms
for (var i:uint=0; i<length; i++)                                   40
for (var i:uint=length; i>0; i--)                                   40
var i:uint = 0; while (i < length) i++;                             40
var i:uint = length; while (--i)                                    52
var i:uint = 0; do {} while (++i < length);                         68
var i:uint = length-1; do {} while (i--);                           68
for (var b:* in arr)                                               224
for each (var b:Boolean in arr)                                    216
for each (var b:* in arr)                                          200
for each (var b:* in arr) var c:Boolean = b as Boolean;            686
arr.forEach(arrForEachF)                                          1446

Performance testing on operations with Number, int, uint. (read more)

Assignment (a:TYPE = 0) ......... min - max (ms)
int:                               24 -  45
Number:                            24 -  36
uint:                              25 -  37
Assignment (a:TYPE = 0.5) ....... min - max (ms)
int:                               56 -  83
Number:                            26 -  43
uint:                              57 -  92
Division (a:TYPE = i/2) ......... min - max (ms)
int:                               60 - 105
Number:                            34 -  64
uint:                             184 - 278
Multiplication (a:TYPE = i*2) ... min - max (ms)
int:                               78 - 129
Number:                            39 -  64
uint:                             207 - 280
Addition (a:TYPE = i+2) ......... min - max (ms)
int:                               31 -  49
Number:                            44 -  55
uint:                              85 - 113
Bitshift (a:TYPE = i<<1) ........ min - max (ms)
int:                               31 -  63
Number:                            61 - 114
uint:                              71 - 130