Boost logo

Boost :

Subject: Re: [boost] [Endian] Performance
From: John Filo (filo_at_[hidden])
Date: 2011-09-07 08:16:26

On 09/05/2011 05:38 PM, Phil Endecott wrote:

> I've just done some quick benchmarks of Beman's proposed byte-swapping
> code using the following test program:
> ...
> What do people see on other platforms?

I added a test case that uses Beman's integer types that yields much
better performance (~2.5X) than the reorder functions in the
conversion portion of the library.

I.e. I added:

     #elif USE_BIG
         return *reinterpret_cast<const ubig32_t*>(&src);
     #elif USE_LITTLE
         return *reinterpret_cast<const ulittle32_t*>(&src);
     #elif USE_NATIVE
         return src;

and on a Intel Core2 with gcc-4.4.3, I get the following results at
-O2 (except where noted, -O3 and -O4 produced nearly identical

   USE_HTONL 1.39
   USE_BEMAN 7.81
   USE_BIG 3.09
   USE_LITTLE 2.95
   USE_NATIVE 0.86 (0.23 for -O3)

So it looks like the mechanism used in the "integers" part of the
library is superior to the mechanism used in the "conversion" part of
the library and maybe the latter should be adapted to use the former.
It seems like for that to work the the "endianness" enum would have to
be extended to include "nonnative". Then the reorder<T> functions
could then be implemented in terms of endian<T, nonnative>.

Boost list run by bdawes at, gregod at, cpdaniel at, john at