>>Would you time the other three options too? I'm really curious and wouldn't be surprised if any of them fared better than bittest.
>
>0.026 - the "array[256]" method - 5 times faster than bittest, as expected...
>0.266 - the "256 variables" method
>0.466 - the "divide by 128,64,..." method
>
>Test was for 10,000 retrieves.
>The array and variables were defined before timing (used... "bittest" method to define them.)
>
>Thanks for all,
>dz
>
>>Hushhhhh.... you don't wanna get that klingo mad! ;-)
>But why, we all know that it was only the humidity that caused him ranting?
Does your time for the array lookup include the time of initializing the array? That is very expensive for few conversions, but a great solution when cached for many conversions.
The following are simple and beat the bittest method by about a third on my machine:
#define NIBBLES "0000000100100011010001010110011110001001101010111100110111101111"
function BYTEtobin(tnInput)
local lcOutput
lcOutput = substr(NIBBLES, 1 + 4 * bitand(bitrshift(tnInput, 4), 0xf), 4) + ;
substr(NIBBLES, 1 + 4 * bitand(tnInput, 0xf), 4)
return lcOutput
function WORDtobin(tnInput)
local lcOutput
lcOutput = substr(NIBBLES, 1 + 4 * bitand(bitrshift(tnInput, 12), 0xf), 4) + ;
substr(NIBBLES, 1 + 4 * bitand(bitrshift(tnInput, 8), 0xf), 4) + ;
substr(NIBBLES, 1 + 4 * bitand(bitrshift(tnInput, 4), 0xf), 4) + ;
substr(NIBBLES, 1 + 4 * bitand(tnInput, 0xf), 4)
return lcOutput
function DWORDtobin(tnInput)
local lcOutput
lcOutput = substr(NIBBLES, 1 + 4 * bitand(bitrshift(tnInput, 28), 0xf), 4) + ;
substr(NIBBLES, 1 + 4 * bitand(bitrshift(tnInput, 24), 0xf), 4) + ;
substr(NIBBLES, 1 + 4 * bitand(bitrshift(tnInput, 20), 0xf), 4) + ;
substr(NIBBLES, 1 + 4 * bitand(bitrshift(tnInput, 16), 0xf), 4) + ;
substr(NIBBLES, 1 + 4 * bitand(bitrshift(tnInput, 12), 0xf), 4) + ;
substr(NIBBLES, 1 + 4 * bitand(bitrshift(tnInput, 8), 0xf), 4) + ;
substr(NIBBLES, 1 + 4 * bitand(bitrshift(tnInput, 4), 0xf), 4) + ;
substr(NIBBLES, 1 + 4 * bitand(tnInput, 0xf), 4)
return lcOutput
Précédent
Suivant
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement