>>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
Previous
Next
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only