Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^2: Fastest byteswap (little endian to big endian (eg. 34127856 -> 12345678)

by afoken (Chancellor)
on Apr 14, 2015 at 15:54 UTC ( [id://1123422]=note: print w/replies, xml ) Need Help??


in reply to Re: Fastest byteswap (little endian to big endian (eg. 34127856 -> 12345678)
in thread Fastest byteswap (little endian to big endian (eg. 34127856 -> 12345678)

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". ;-)

Replies are listed 'Best First'.
Re^3: Fastest byteswap (little endian to big endian (eg. 34127856 -> 12345678)
by pme (Monsignor) on Apr 14, 2015 at 19:05 UTC
    Hi afoken

    I can make dd even faster adding 'bs=20M' (default ibs=obs=512 in according to the man page).

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1123422]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (5)
As of 2024-04-18 15:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found