Re: xxd -i vs DIY Was: C23 thoughts and opinions

Liste des GroupesRevenir à cl c  
Sujet : Re: xxd -i vs DIY Was: C23 thoughts and opinions
De : already5chosen (at) *nospam* yahoo.com (Michael S)
Groupes : comp.lang.c
Date : 29. May 2024, 14:23:25
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20240529152325.000042e1@yahoo.com>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
User-Agent : Claws Mail 3.19.1 (GTK+ 2.24.33; x86_64-w64-mingw32)
On Wed, 29 May 2024 12:23:51 +0100
bart <bc@freeuk.com> wrote:

On 29/05/2024 10:38, Michael S wrote:
On Wed, 29 May 2024 00:54:23 +0100
bart <bc@freeuk.com> wrote:
 
>
I suspect that your system just has a much faster fgetc
implementation. How long does an fgetc() loop over a 100MB input
take on your machine?
>
On mine it's about 2 seconds on Windows, and 3.7 seconds on WSL.
Using DMC, it's 0.65 seconds.
 
 
Your suspicion proved incorrect, but it turned out to be pretty good
question!
 
 
 
$ time ../quick_xxd/getc_test.exe uu.txt
193426754 byte. xor sum 1.
 
real    0m3.604s
user    0m0.000s
sys     0m0.000s
 
52 MB/s. Very very slow! 
 
I got these results for a 100MB input. All are optimised where
possible:
 
mcc      1.9  seconds
gcc      1.9
tcc      1.95
lccwin32 0.7
DMC      0.7
 
The first three likely just use fgetc from msvcrt.dll. The other two
probably use their own libraries.
 
So, may be, fgetc() is not at fault? May be, its OS and the crap
that the corporate IT adds on top of the OS? 
 
 
 
Let's test this hipothesys. 
 
$ time ../quick_xxd/fread_test.exe uu.txt
193426754 byte. xor sum 1.
 
real    0m0.094s
user    0m0.000s
sys     0m0.000s 
 
I get these results:
 
mcc      0.25 seconds
gcc      0.25
tcc      0.35
lccwin32 0.35
DMC      0.3
 
All are repeated runs of the same file, so all timings likely used
cached version of the data file.
 
Most of my tests assume that since (1) I don't know how to to do a
'cold' load without restarting my machines; (2) in real applications
such as compilers the same files are repeatedly processed anyway, eg.
you're compiling the file you've just edited, or just downloaded, or
just copied...
 
So, let's rewrite our tiny app with fread(). 
 
real    0m0.577s
user    0m0.000s
sys     0m0.000s
 
152.8 MB/s. That's much better. Some people would even say that it
is good enough. 
 
I now get:
 
mcc      2.3 seconds
gcc      1.6
tcc      2.3
lccwin32 2.9
DMC      2.9
>

Mine was with MSVC from VS2019. gcc on msys2 (ucrt64 variant) should be
identical.
I wonder why your results are so much slower than mine.
Slow write speed of SSD or slow CPU?

You might remember that the last revised version of your test,
compiled with gcc, took 3.6 seconds, of which 2 seconds was reading
the file a byte at a time took 2 seconds.
 
By using a 128KB buffer, you get most of the benefits of reading the
whole file at once

I hope so.

(it just lacks the simplicity).

The simplicity in your case is due to complexity of figuring out the
size of the file and of memory allocation and of handling potential
failure of memory allocation all hidden within run-time library of your
language.
And even despite all the upfront work that went into your
infrastructure, it probably would not be able to deal with big files on
32-bit system.
Yes, I know, 32-bit compiler would not be able to compile the resulting
big include anyway. But still...

So nearly all of that 2 seconds is saved.
 
3.6 - 2.0 is 1.6, pretty much the timing here.
 
 
 >Two hours later it turned out to be completely incorrect. That is,
 >the 
time was spent in routine related to I/O, but in the 'soft' part of it
rather than in the I/O itself.
 
You don't count time spent within file-functions as I/O? To me 'I/O'
is whatever happens the other side of those f* functions, including
whatever poor buffering strategies they could be using.
 
Because 'fgetc' could also have been implemented using a 128KB buffer
instead of 512 bytes or whatever it uses.
 
I discovered the poor qualities of fgetc many years ago and generally
avoid it; it seems you've only just realised its problems.
 

Octet-by-octet processing of big files is not how I earn butter to put
on my bread.
When I write this sort of utilities for real work, the size of the
input is not arbitrary. Typically I deal with small files (small
relatively to memory capacity of target machines, so 100 MB is still
considered small). So for real work more often than not I use the same
strategy as your did in the program in your language.

BTW I also tweaked the code in my own-language version of the
benchmark. (I also ported it to C, but that version got accidentally
deleted). The fastest timing of this test is now 1.65 seconds.
 
If I comment out the 'fwrite' call, the timing becomes 0.7 seconds,
of which 50ms is reading in the file, leaving 0.65 seconds.
 
So the I/O in this case accounts for 1.0 seconds of the 1.65 seconds
runtime, so when I said:
 
 >I think runtime is still primarily spent in I/O. 
 
That was actually correct.
 

That was incorrect for the previous variant of my program.
Quite likely, it was correct for the program in your language that was
loading a full file before processing.
Quite likely it is correct for my latest variant.
Pay attention how I remember to avoid categorical statements ;-)

If I comment out the 'fwrite' calls in your program, the runtime
reduces to 0.2 seconds, so it is even more correct in that case. Or
is 'fwrite' a 'soft' I/O call too?
 

I think not (on my test gear), but I no longer know.
However I suspect that on Linux with plenty of memory the program could
return before even a single byte of output data was sent to SSD.



Date Sujet#  Auteur
22 May 24 * C23 thoughts and opinions524David Brown
22 May 24 +* Re: C23 thoughts and opinions355Thiago Adams
22 May 24 i+* Re: C23 thoughts and opinions352David Brown
22 May 24 ii+* Re: C23 thoughts and opinions22Thiago Adams
23 May 24 iii`* Re: C23 thoughts and opinions21David Brown
23 May 24 iii `* Re: C23 thoughts and opinions20Thiago Adams
23 May 24 iii  +* Re: C23 thoughts and opinions18David Brown
23 May 24 iii  i`* Re: C23 thoughts and opinions17Thiago Adams
23 May 24 iii  i `* Re: C23 thoughts and opinions16Keith Thompson
24 May 24 iii  i  +- Re: C23 thoughts and opinions1David Brown
24 May 24 iii  i  `* Re: C23 thoughts and opinions14Thiago Adams
24 May 24 iii  i   `* Re: C23 thoughts and opinions13Keith Thompson
24 May 24 iii  i    `* Re: C23 thoughts and opinions12Thiago Adams
24 May 24 iii  i     `* Re: C23 thoughts and opinions11Keith Thompson
25 May 24 iii  i      `* Re: C23 thoughts and opinions10Thiago Adams
25 May 24 iii  i       +* Re: C23 thoughts and opinions4Keith Thompson
25 May 24 iii  i       i`* Re: C23 thoughts and opinions3Thiago Adams
25 May 24 iii  i       i `* Re: C23 thoughts and opinions2David Brown
26 May 24 iii  i       i  `- Re: C23 thoughts and opinions1Keith Thompson
25 May 24 iii  i       `* Re: C23 thoughts and opinions5David Brown
25 May 24 iii  i        `* Re: C23 thoughts and opinions4Thiago Adams
25 May 24 iii  i         +* Re: C23 thoughts and opinions2David Brown
26 May 24 iii  i         i`- Re: C23 thoughts and opinions1bart
6 Jun 24 iii  i         `- Re: C23 thoughts and opinions1Thiago Adams
23 May 24 iii  `- Re: C23 thoughts and opinions1Thiago Adams
23 May 24 ii+* Re: C23 thoughts and opinions323Keith Thompson
23 May 24 iii+* Re: C23 thoughts and opinions313Thiago Adams
23 May 24 iiii`* Re: C23 thoughts and opinions312bart
23 May 24 iiii +* Re: C23 thoughts and opinions309David Brown
23 May 24 iiii i`* Re: C23 thoughts and opinions308Keith Thompson
24 May 24 iiii i +- Re: C23 thoughts and opinions1David Brown
25 May 24 iiii i +* Re: C23 thoughts and opinions305Keith Thompson
25 May 24 iiii i i`* Re: C23 thoughts and opinions304David Brown
26 May 24 iiii i i `* Re: C23 thoughts and opinions303Keith Thompson
26 May 24 iiii i i  +* Re: C23 thoughts and opinions300David Brown
26 May 24 iiii i i  i+* Re: C23 thoughts and opinions17bart
26 May 24 iiii i i  ii`* Re: C23 thoughts and opinions16Michael S
26 May 24 iiii i i  ii `* Re: C23 thoughts and opinions15bart
26 May 24 iiii i i  ii  `* Re: C23 thoughts and opinions14Michael S
26 May 24 iiii i i  ii   +* Re: C23 thoughts and opinions3bart
26 May 24 iiii i i  ii   i`* Re: C23 thoughts and opinions2Michael S
26 May 24 iiii i i  ii   i `- Re: C23 thoughts and opinions1bart
26 May 24 iiii i i  ii   +* Re: C23 thoughts and opinions5Malcolm McLean
26 May 24 iiii i i  ii   i`* Re: C23 thoughts and opinions4Michael S
27 May 24 iiii i i  ii   i `* Re: C23 thoughts and opinions3Lawrence D'Oliveiro
27 May 24 iiii i i  ii   i  +- Re: C23 thoughts and opinions1Chris M. Thomasson
27 May 24 iiii i i  ii   i  `- Re: C23 thoughts and opinions1David Brown
26 May 24 iiii i i  ii   +- Re: C23 thoughts and opinions1Michael S
26 May 24 iiii i i  ii   +- Re: C23 thoughts and opinions1bart
27 May 24 iiii i i  ii   +- Re: C23 thoughts and opinions1Keith Thompson
27 May 24 iiii i i  ii   `* Re: C23 thoughts and opinions2Lawrence D'Oliveiro
27 May 24 iiii i i  ii    `- Re: C23 thoughts and opinions1Michael S
26 May 24 iiii i i  i+- Re: C23 thoughts and opinions1Thiago Adams
27 May 24 iiii i i  i+* Re: C23 thoughts and opinions66Keith Thompson
27 May 24 iiii i i  ii+* Re: C23 thoughts and opinions62David Brown
28 May 24 iiii i i  iii`* Re: C23 thoughts and opinions61Keith Thompson
28 May 24 iiii i i  iii `* Re: C23 thoughts and opinions60David Brown
28 May 24 iiii i i  iii  `* Re: C23 thoughts and opinions59Keith Thompson
28 May 24 iiii i i  iii   +- Re: C23 thoughts and opinions1Michael S
29 May 24 iiii i i  iii   `* Re: C23 thoughts and opinions57David Brown
14 Jun 24 iiii i i  iii    `* Re: C23 thoughts and opinions56Keith Thompson
15 Jun 24 iiii i i  iii     +* Re: C23 thoughts and opinions12bart
15 Jun 24 iiii i i  iii     i`* Re: C23 thoughts and opinions11David Brown
15 Jun 24 iiii i i  iii     i `* Re: C23 thoughts and opinions10bart
16 Jun 24 iiii i i  iii     i  +* Re: C23 thoughts and opinions5Lawrence D'Oliveiro
16 Jun 24 iiii i i  iii     i  i`* Re: C23 thoughts and opinions4bart
16 Jun 24 iiii i i  iii     i  i +- Re: C23 thoughts and opinions1Lawrence D'Oliveiro
16 Jun 24 iiii i i  iii     i  i `* Re: C23 thoughts and opinions2Chris M. Thomasson
17 Jun 24 iiii i i  iii     i  i  `- Re: C23 thoughts and opinions1Lawrence D'Oliveiro
16 Jun 24 iiii i i  iii     i  `* Re: C23 thoughts and opinions4David Brown
16 Jun 24 iiii i i  iii     i   `* Re: C23 thoughts and opinions3bart
17 Jun 24 iiii i i  iii     i    +- Re: C23 thoughts and opinions1David Brown
17 Jun 24 iiii i i  iii     i    `- Re: C23 thoughts and opinions1Michael S
15 Jun 24 iiii i i  iii     +* Re: C23 thoughts and opinions3David Brown
16 Jun 24 iiii i i  iii     i`* Re: C23 thoughts and opinions2Lawrence D'Oliveiro
16 Jun 24 iiii i i  iii     i `- Re: C23 thoughts and opinions1David Brown
17 Jun 24 iiii i i  iii     `* Hex string literals (was Re: C23 thoughts and opinions)40Keith Thompson
17 Jun 24 iiii i i  iii      +* Re: Hex string literals (was Re: C23 thoughts and opinions)20David Brown
18 Jun 24 iiii i i  iii      i+* Re: Hex string literals (was Re: C23 thoughts and opinions)18Keith Thompson
18 Jun 24 iiii i i  iii      ii+* Re: Hex string literals (was Re: C23 thoughts and opinions)2Lawrence D'Oliveiro
18 Jun 24 iiii i i  iii      iii`- Re: Hex string literals (was Re: C23 thoughts and opinions)1Keith Thompson
18 Jun 24 iiii i i  iii      ii`* Re: Hex string literals (was Re: C23 thoughts and opinions)15David Brown
19 Jun 24 iiii i i  iii      ii +* Re: Hex string literals (was Re: C23 thoughts and opinions)6Keith Thompson
19 Jun 24 iiii i i  iii      ii i`* Re: Hex string literals (was Re: C23 thoughts and opinions)5David Brown
19 Jun 24 iiii i i  iii      ii i `* Re: Hex string literals (was Re: C23 thoughts and opinions)4Kaz Kylheku
19 Jun 24 iiii i i  iii      ii i  `* Re: Hex string literals (was Re: C23 thoughts and opinions)3Michael S
19 Jun 24 iiii i i  iii      ii i   +- Re: Hex string literals (was Re: C23 thoughts and opinions)1bart
19 Jun 24 iiii i i  iii      ii i   `- Re: Hex string literals (was Re: C23 thoughts and opinions)1Michael S
19 Jun 24 iiii i i  iii      ii `* Re: Hex string literals (was Re: C23 thoughts and opinions)8Lawrence D'Oliveiro
19 Jun 24 iiii i i  iii      ii  +* Re: Hex string literals (was Re: C23 thoughts and opinions)6David Brown
21 Jun 24 iiii i i  iii      ii  i`* Re: Hex string literals (was Re: C23 thoughts and opinions)5Lawrence D'Oliveiro
21 Jun 24 iiii i i  iii      ii  i +* Re: Hex string literals (was Re: C23 thoughts and opinions)3David Brown
22 Jun 24 iiii i i  iii      ii  i i`* Re: Hex string literals (was Re: C23 thoughts and opinions)2Lawrence D'Oliveiro
22 Jun 24 iiii i i  iii      ii  i i `- Re: Hex string literals (was Re: C23 thoughts and opinions)1David Brown
21 Jun 24 iiii i i  iii      ii  i `- Re: Hex string literals (was Re: C23 thoughts and opinions)1James Kuyper
19 Jun 24 iiii i i  iii      ii  `- Re: Hex string literals (was Re: C23 thoughts and opinions)1Keith Thompson
18 Jun 24 iiii i i  iii      i`- Re: Hex string literals (was Re: C23 thoughts and opinions)1Lawrence D'Oliveiro
17 Jun 24 iiii i i  iii      +* Re: Hex string literals (was Re: C23 thoughts and opinions)5Richard Kettlewell
17 Jun 24 iiii i i  iii      i+- Re: Hex string literals (was Re: C23 thoughts and opinions)1Richard Kettlewell
18 Jun 24 iiii i i  iii      i`* Re: Hex string literals (was Re: C23 thoughts and opinions)3Keith Thompson
18 Jun 24 iiii i i  iii      i +- Re: Hex string literals (was Re: C23 thoughts and opinions)1Lawrence D'Oliveiro
18 Jun 24 iiii i i  iii      i `- Re: Hex string literals (was Re: C23 thoughts and opinions)1Richard Kettlewell
17 Jun 24 iiii i i  iii      `* Re: Hex string literals (was Re: C23 thoughts and opinions)14bart
28 May 24 iiii i i  ii+* Re: C23 thoughts and opinions2Keith Thompson
28 May 24 iiii i i  ii`- Re: C23 thoughts and opinions1Malcolm McLean
27 May 24 iiii i i  i+* Re: C23 thoughts and opinions121Lawrence D'Oliveiro
28 May 24 iiii i i  i`* xxd -i vs DIY Was: C23 thoughts and opinions94Michael S
28 May 24 iiii i i  `* Re: C23 thoughts and opinions2Keith Thompson
12 Jun 24 iiii i `- Re: C23 thoughts and opinions1Bonita Montero
23 May 24 iiii `* Re: C23 thoughts and opinions2Keith Thompson
23 May 24 iii+* Re: C23 thoughts and opinions7Thiago Adams
23 May 24 iii`* Re: C23 thoughts and opinions2David Brown
23 May 24 ii`* Re: C23 thoughts and opinions6Michael S
23 May 24 i`* Re: C23 thoughts and opinions2Lawrence D'Oliveiro
22 May 24 +* Re: C23 thoughts and opinions10Malcolm McLean
22 May 24 +* Re: C23 thoughts and opinions9Chris M. Thomasson
23 May 24 +* Re: C23 thoughts and opinions2Lawrence D'Oliveiro
23 May 24 +* Re: C23 thoughts and opinions14Michael S
23 May 24 +* Re: C23 thoughts and opinions - why so conservative?37Michael S
23 May 24 +* Re: C23 thoughts and opinions94Bonita Montero
25 May 24 `* Re: C23 thoughts and opinions2Thiago Adams

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal