IntToStr in dll:
http://foryouandi.com/Programs/index.php
I didn't see a difference.
Printable View
IntToStr in dll:
http://foryouandi.com/Programs/index.php
I didn't see a difference.
After looking at my code I realized that it was taking so long to test if every number output from IntToStr correctly because I was redrawing the window for every number. I changed that and now the test completes in about an hour on my computer.
You'll be happy to know that every integer output exacly as itoa does. The only thing that does not is negative hex. I'll work on that.
Did anyone else test the dll version yet to see if IntToStr is faster than itoa on your computer?
My function is slower when working with 64 bit integers than _i64toa is. So I removed some parts of the code and put it in it's own function to show that the bottle neck is. Removing the parts I removed below doesn't really speed the function up at all so that bottleneck is obvious. Take a look.
Any ideas on how to optimize this function for 64 bit?PHP Code:char* IntToStr(int64 n, char* buf, uint radix= 10)
{
if(!n)
{
return "0";
}
static const uint bitCount= 64;
char* ptr= buf+bitCount;
*ptr= 0; //Terminating NULL
/*if(radix == 2)
{
int64 bitPos= 1;
for(register uint i= 0; i < bitCount; ++i)
{
--ptr; *ptr= (n & bitPos) ? '1' : '0'; bitPos= bitPos << 1;
}
return buf;
}
bool neg= n < 0; bool negMax= 0;
if(neg)
{
n= -n;
if(n < 0)
{
negMax= 1;
n= ~n; //make posotive max
}
}
if(radix == 16) //hex
{
static const char* itoaChars= "0123456789abcdefghijklmnopqrstuvwxyz";
while(n > 0)
{
--ptr;
*ptr= itoaChars[n%radix];
n /= radix;
}
}
else*/
{
while(n > 0) //bottleneck here! Speed up for 64 bit
{
--ptr;
*ptr= n%radix+'0';
n /= radix;
}
}
/*if(neg)
{
--ptr;
*ptr= '-';
}
if(negMax && radix == 10)
{
char* ptr2= buf+(bitCount-1);
while(*ptr2 == '9')
{
*ptr2= '0';
--ptr2;
}
if(*ptr2 == '7') *ptr2= '8';
else if(*ptr2 == '0') *ptr2= '1';
else if(*ptr2 == '1') *ptr2= '2';
else if(*ptr2 == '2') *ptr2= '3';
else if(*ptr2 == '3') *ptr2= '4';
else if(*ptr2 == '4') *ptr2= '5';
else if(*ptr2 == '5') *ptr2= '6';
else if(*ptr2 == '6') *ptr2= '7';
else if(*ptr2 == '8') *ptr2= '9';
}*/
return ptr;
}
I uploaded a new program so that you can see for yourselves if 64 bit is slower on your computer. Just change testWith64 to 1.
http://foryouandi.com/Programs/index.php
You need to get a code profiler so that you know where the slowdown is actually taking place instead of making guesses.
Regards,
Paul McKenzie