Originally Posted by
quzah
Code:
void bar( char s[], long l )
{
char buf[ BUFSIZ ] = {0};
char *p = buf, *q = s;
size_t comma = 0, trail = 0;
sprintf( buf, "%ld", l );
if( *p == '-' )
*q++ = *p++;
for( trail = strlen( p ) % 3; trail > 0; trail-- )
{
*q++ = *p++;
}
for( comma = strlen( p ) / 3; comma > 0; comma-- )
{
*q++ = ',';
*q++ = *p++;
*q++ = *p++;
*q++ = *p++;
}
}
Quzah.
Hi quzah. Did you test it? how long it is going to take for the
whole range of integers? Did you see my previous post?
The use of:
Code:
sprintf( buf, "%ld", l );
makes me think it is going to be quite slow.
Edit: the simple sprintf() cycle takes:
Code:
Testing version : Sprintf()
------------------------------------
Testing on Intel Core 2 Duo E6600 2.4 Ghz // IA32
OS = Windows 7 Ultimate 64 bit -- Compiler = Pelles C 6.00.4
Testing the numbers from: 0 to 100,000,000
The generating process has taken: 43,633 ms to perform the whole cycle
using this code:
Code:
for (x = 0; x < times; x++){
sprintf( buffer, "%ld", x );
} // end x for
quite slow indeed for testing 4 billion combinations it is going to take
more or less 20' by itself.