Write in C. ;)

Has already been done, ages before this question was posted, because this problem is ages old. And dd is significantly faster (97 msec) even on my old server:

$ time dd if=tmp/TestFile.bin conv=swab of=tmp/TestFile.out 32768+0 records in 32768+0 records out 16777216 bytes (17 MB) copied, 0.0970995 s, 173 MB/s real 0m0.130s user 0m0.020s sys 0m0.080s $ od -h tmp/TestFile.bin | head 0000000 0000 0000 0000 0000 0000 0000 0000 0000 0000020 0000 0000 0fac e0ff 0000 0000 dead beef 0000040 0000 0000 0000 0000 0000 0000 0000 7800 0000060 0000 0000 0000 0000 0000 0000 0000 0000 * 0001000 4946 4900 0000 0001 0000 0002 0000 0000 0001020 ffff ffff ffff ffff ffff ffff ffff ffff * 0002000 0000 0001 0000 000b 0000 0000 00ef fc00 0002020 0000 0000 0000 0400 0000 0000 0002 e800 $ od -h tmp/TestFile.out | head 0000000 0000 0000 0000 0000 0000 0000 0000 0000 0000020 0000 0000 ac0f ffe0 0000 0000 adde efbe 0000040 0000 0000 0000 0000 0000 0000 0000 0078 0000060 0000 0000 0000 0000 0000 0000 0000 0000 * 0001000 4649 0049 0000 0100 0000 0200 0000 0000 0001020 ffff ffff ffff ffff ffff ffff ffff ffff * 0002000 0000 0100 0000 0b00 0000 0000 ef00 00fc 0002020 0000 0000 0000 0004 0000 0000 0200 00e8 $

Just for fun, doing the same thing on a cdrom image file:

$ time dd slackware-13.0-install-d2.iso conv=swab of=tmp/delete.me 1315400+0 records in 1315400+0 records out 673484800 bytes (673 MB) copied, 4.05028 s, 166 MB/s real 0m4.173s user 0m0.640s sys 0m3.370s $

The speed of dd on my server is clearly limited by the disks, as working on a tmpfs in RAM runs at about double speed compared to running with files on disk:

$ time dd if=/tmp/TestFile.bin conv=swab of=/tmp/TestFile.out 32768+0 records in 32768+0 records out 16777216 bytes (17 MB) copied, 0.0506392 s, 331 MB/s real 0m0.056s user 0m0.020s sys 0m0.030s $

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

In reply to Re^2: Fastest byteswap (little endian to big endian (eg. 34127856 -> 12345678) by afoken
in thread Fastest byteswap (little endian to big endian (eg. 34127856 -> 12345678) by james28909

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.