Sujet : Re: xxd -i vs DIY Was: C23 thoughts and opinions
De : bc (at) *nospam* freeuk.com (bart)
Groupes : comp.lang.cDate : 29. May 2024, 21:31:54
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v383bp$19tqg$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
User-Agent : Mozilla Thunderbird
On 29/05/2024 18:41, bart wrote:
Below is a version with no declarations at all. It is in a dynamic scripting language.
It runs in 7.3 seconds (or 6.4 seconds if newlines are dispensed with).
That is slower that native code solutions, but it is still faster than xxd!
My scripting language doesn't normally run under Linux (to make the comparison with xxd fairer), but I managed to make it work for this test:
C:\qx52>mc -c -linux qc
M6 Compiling qc.m to qc.c
C:\qx52>wsl
root@DESKTOP-11:/mnt/c/qx52# gcc -O3 qc.c -o qc -lm -ldl -fno-builtin
root@DESKTOP-11:/mnt/c/qx52# time ./qc -nosys fred
real 0m10.562s
user 0m9.198s
sys 0m0.681s
root@DESKTOP-11:/mnt/c/qx52#
I start off under Windows, run a transpiler on a special version of it that is transpilable, then compile that C file it under WSL. (The -nosys option leaves out standard libs using WinAPI.)
It takes 10.5 seconds; not as fast as on Windows, but there I'm using an accelerator which needs inline assembly, which I can't turn into C.
Here is how xxd fared on a slightly faster second run:
root@DESKTOP-11:/mnt/c/qx52# time xxd -i <data100 >xxd.txt
real 0m33.066s
Conclusion: beating xxd is apparently not hard if even a scripting language can do so. I wonder what slows it down? The output format is more bloated, but that can only be part of it.