Re: Best practice for data encoding?

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

 



Ted Faber wrote:

On Mon, Jun 12, 2006 at 02:11:19PM +0200, Iljitsch van Beijnum wrote:
The problem with text is that you have to walk through memory and compare characters. A LOT.

That's not where your code spends its time.

Run gprof(1).  The majority of time your code spends is spent doing the
2 integer divides per text to integer conversion and in strtoimax
(called by fscanf).
Multiplying or dividing is the worst thing you can do on a CPU in
general.
Note that CPUs are different; some multiply faster than others, compared to the rest of the HW.

And if you really need to, you can optimize... a multiplication by 10, for instance, can be done by two left shifts and an addition (a*10 = a <<3 + a<<1); I have no idea why strtoimax would do divisions, but I haven't written decimal-number parsers for a very long time; I think Knuth had 3 different ones in "Seminumerical algorithms", but that was a VERY long time ago...

                    Harald




_______________________________________________

Ietf@xxxxxxxx
https://www1.ietf.org/mailman/listinfo/ietf

[Index of Archives]     [IETF Annoucements]     [IETF]     [IP Storage]     [Yosemite News]     [Linux SCTP]     [Linux Newbies]     [Fedora Users]