Re: Question regarding sscanf() vs. off_t and similar

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thursday 14 September 2006 17:41 Andreas Schwab wrote:
> Philipp Marek <philipp@xxxxxxxxxxxxx> writes:
> > On Thursday 14 September 2006 15:01 Andreas Schwab wrote:
> >> Note that "L" is not a valid length modifier for integer formats.
> >
> > For gnu libc it is:
> > http://www.gnu.org/software/libc/manual/html_node/Integer-Conversions.htm
> >l#Integer-Conversions
> It's better not to depend on non-standard extensions when it is easy to
> avoid.
There you're right.

> >> Assuming you meant %llu instead of %Lu you can always add a cast to
> >> unsigned long long to match the format.
> >
> > Yes. But that's a bit unclean, and doing that unnecessarily in a loop for
> > ~300000 iterations is something I'd like to avoid.
>
> String formatting isn't exactly fast anyway, so the conversion would most
> likely be lost in the noise.

Trying the attached program seems to show that it makes up to 30% difference 
(in a microbenchmark - not in the real-world-scenario :-)

	$ cc -O6 -o pf pf.c
	$ ./pf
	stg=1799999

	diff = 1:018974
	diff = 1:340017
(Thats on an Duron 1200)

Thank you!


Regards,

Phil

-- 
Versioning your /etc, /home or even your whole installation?
             Try fsvs (fsvs.tigris.org)!
t: pf
	./pf

pf: pf.c
	$(CC) -O6 -o $@ $<

#include <sys/time.h>
#include <time.h>



#define RUNS 1800000

void P(struct timeval *a, struct timeval *b)
{
  int sec=b->tv_sec - a->tv_sec;
  int usec=b->tv_usec - a->tv_usec;

	if (usec<0) { usec+=1000000; sec--; }

	printf("diff = %d:%06d\n", sec, usec);
}

main()
{
  char stg[30];
	int i;
	struct timeval tv1, tv2, tv3;
	struct timezone tz;

	gettimeofday(&tv1, &tz);
	for(i=0; i<RUNS; i++)
	{
	  sprintf(stg, "%ld \n", (long)i);
	}
	gettimeofday(&tv2, &tz);
	for(i=0; i<RUNS; i++)
	{
	  sprintf(stg, "%Ld \n", (long long)i);
	}
	gettimeofday(&tv3, &tz);

	printf("stg=%s\n", stg);
	P(&tv1, &tv2);
	P(&tv2, &tv3);

}
_______________________________________________
Autoconf mailing list
Autoconf@xxxxxxx
http://lists.gnu.org/mailman/listinfo/autoconf

[Index of Archives]     [GCC Help]     [Kernel Discussion]     [RPM Discussion]     [Red Hat Development]     [Yosemite News]     [Linux USB]     [Samba]

  Powered by Linux