How fast is the procedure to convert from using big endian to little endian?
views:
194answers:
2
+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
2009-09-24 14:43:50
Even if using perl's pack?
innaM
2009-09-24 14:46:00
@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
2009-09-24 15:09:01
Can you provide an example opcode or post a link to where I can find an example? Thanks.
Davie
2009-09-24 16:34:51
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
2009-09-24 16:49:14
+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
2009-09-24 14:57:40