You are here: Re: Any Intelligent Thoughts On This? « All PHP « IT news, forums, messages
Re: Any Intelligent Thoughts On This?

Posted by Jeckyl on 01/20/07 23:48

OK .. to save you the trouble (and for the benefit of anyone who may be
deceived into thinking that hatter actually knows what he talks about),
here's the tests and results:

First one, just in case you really DO want / need the actual 6-digit hex
string from a getPixel value (and not the R,G,B components):

>>
// a rgb color number to convert
// note, if I change it to (say) 12345 the hatter method fails
clr = 12345;

// the first method is what hatter does
// converts the color to a hex string
// and prepends a "0" if required
// (note: this fails if the red component
// is zero.)
t0 = getTimer();
for (i = 0; i < 10000; i++) {
color_pick = clr.toString(16);
if (color_pick.length < 6) color_pick = '0' + color_pick;
}
t1 = getTimer();

// this m,ethod pads and extracts with
// no need for a test and does not fail
t2 = getTimer();
for (i = 0; i < 10000; i++) {
color_pick = ("000000"+clr.toString(16)).substr(-6);
}
t3 = getTimer();

hatter = t1-t0;
jeckyl = t3-t2;
>>
RESULTS: hatter method takes 415 ms, my method takes 325. Any my method
works with all possible getPixel results values .. hatters doesn't

Now, if its the whole process of going from getPixel value to separate r,g,b
values that is required, as hatter uses in the character animation swf that
he keeps posting links to, then we can test that as well:

>>
// a rgb color number to convert
// note, if I change it to (say) 12345 the hatter method fails
clr = 123456;

// the first method is what hatter does
// converts the color to a hex string
// converts that to upper case (unneeded)
// extract hex substrings of 2 characters each
// and converts them to numbers
t0 = getTimer();
for (i = 0; i < 10000; i++) {
color_pick = clr.toString(16).toUpperCase();
if (color_pick.length < 6) color_pick = '0' + color_pick;
r = parseInt(color_pick.substr(0,2),16);
g = parseInt(color_pick.substr(2,2),16);
b = parseInt(color_pick.substr(4,2),16);
}
t1 = getTimer();

// this is what I'd do
// for each rgb component byte
// mask off the bottom byte
// then shift the value to get to the next byte
t2 = getTimer();
for (i = 0; i < 10000; i++) {
tmp = clr;
b = tmp & 255;
tmp >>= 8;
g = tmp & 255;
tmp >>= 8;
r = tmp & 255;
}
t3 = getTimer();

hatter = t1-t0;
jeckyl = t3-t2;
>>

RESULTS: hatter method takes 1384ms, my method takes 240ms. If you use
Flash 8 instead of SWiSH Max, you can get it a bit faster still .. but as it
is it is over 5 times faster (close to 6 times)

Wonder where hatter made up this 700% slower figure from .. maybe he just
had no idea how to measure it, or had no idea how to implement it, or both.
That would seem consistent with my experiences with him so far .. that he's
just a big ugly bag of foul language .. nothing logical, rational or
intelligent has come out of him so far.
--
Jeckyl.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация