views:

194

answers:

2

How fast is the procedure to convert from using big endian to little endian?

+4  A: 

Very fast. It's a single machine language opcode on most architectures. Even on ancient hardware it would execute in only 2-3 clock cycles.

Brian Knoblauch
Even if using perl's pack?
innaM
@Manni I can't speak as to how well Perl actually implements it. The hardware itself is capable of doing it extremely fast. In fact, I believe that it's the SPARC architecture where it allows for memory pages to be either be big or little and then you don't even have to execute an instruction to swap. Handled automagically by the retrieval unit.
Brian Knoblauch
Can you provide an example opcode or post a link to where I can find an example? Thanks.
Davie
The XCHG or BSWAP ops on x86 machines. "xchg ah, al" or "bswap eax" IIRC. My assembly is a little rusty, don't do much in it anymore.
Brian Knoblauch
+1  A: 

The speed greatly depends on the implementation and the language. Inlined machine code is extremely fast but an implementation running in an interpreted language may be orders of magnitude slower. If it's not inlined, procedure call overhead may take considerably more time than the actual byte swap.

Uh Clem