Re: [Toybox] [PATCH] xxd: -d Decimal Lables flag, Don't cap at one file

2024-04-22 Thread Rob Landley
On 4/22/24 17:17, enh via Toybox wrote:
> ah, yeah, the _include_ path uses the full buffer and -r uses stdio
> buffering, but "regular" xxd was doing neither. i've sent out the
> trivial patch to switch to stdio.

Ah, performance tweak.

*shrug* Applied...

Rob
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


Re: [Toybox] [PATCH] xxd: -d Decimal Lables flag, Don't cap at one file

2024-04-22 Thread Oliver Webb via Toybox
On Monday, April 22nd, 2024 at 17:17, enh via Toybox  
wrote:

> ah, yeah, the include path uses the full buffer and -r uses stdio
> buffering, but "regular" xxd was doing neither. i've sent out the
> trivial patch to switch to stdio.

Thanks, on my machine it improves the speed by about 10Mb/s (~15Mb/s -> 
~25Mb/s).

- Oliver Webb aquahobby...@proton.me

___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


Re: [Toybox] [PATCH] xxd: -d Decimal Lables flag, Don't cap at one file

2024-04-22 Thread enh via Toybox
On Mon, Apr 22, 2024 at 2:23 PM Oliver Webb  wrote:
>
> > On Sat, Apr 20, 2024 at 7:38 PM Oliver Webb via Toybox
> > toybox@lists.landley.net wrote:
>
> > > xxd also runs on average about 5 times slower than vim xxd, this is
> > > because of read reading 16 bytes at a time, also not hard to fix, but
> > > very hard to fix cleanly.
> >
> >
> > really? a quick glance suggests it reads blocks of sizeof(toybuf)? (or
> > "whatever stdio is using for its buffer" in the -r case.)
>
> strace-ing it shows:
>
> read(0, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 16) = 16
>
> And if you pass in -c 12 to it:
>
> read(0, "\0\0\0\0\0\0\0\0\0\0\0\0", 12) = 12
>
> In practice, it's always what -c is

ah, yeah, the _include_ path uses the full buffer and -r uses stdio
buffering, but "regular" xxd was doing neither. i've sent out the
trivial patch to switch to stdio.

> > > xxd has a -d flag to do decimal address lables that I added in this patch.
> >
> > do you have a use for that? i saw it and ignored it when
> > implementing toybox xxd because i couldn't even imagine a use for
> > decimal addresses...
>
> Trying to do math with them in awk or expr or some other program where numbers
> are always read as base 10:
>
> $ head -c 0xf
> head: invalid number of bytes: ‘0xf’
>
> I think the ability to read base 16 numbers and prefixes in toybox is a really
> cool consequence of everything being in one binary. But almost every other 
> utility
> set doesn't have it because most aren't multi-call binaries.
>
> - Oliver Webb aquahobby...@proton.me
>
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


Re: [Toybox] [PATCH] xxd: -d Decimal Lables flag, Don't cap at one file

2024-04-22 Thread Oliver Webb via Toybox
> On Sat, Apr 20, 2024 at 7:38 PM Oliver Webb via Toybox
> toybox@lists.landley.net wrote:

> > xxd also runs on average about 5 times slower than vim xxd, this is
> > because of read reading 16 bytes at a time, also not hard to fix, but
> > very hard to fix cleanly.
> 
> 
> really? a quick glance suggests it reads blocks of sizeof(toybuf)? (or
> "whatever stdio is using for its buffer" in the -r case.)
 
strace-ing it shows:

read(0, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 16) = 16

And if you pass in -c 12 to it:

read(0, "\0\0\0\0\0\0\0\0\0\0\0\0", 12) = 12

In practice, it's always what -c is

> > xxd has a -d flag to do decimal address lables that I added in this patch.
> 
> do you have a use for that? i saw it and ignored it when
> implementing toybox xxd because i couldn't even imagine a use for
> decimal addresses...

Trying to do math with them in awk or expr or some other program where numbers
are always read as base 10:

$ head -c 0xf
head: invalid number of bytes: ‘0xf’

I think the ability to read base 16 numbers and prefixes in toybox is a really
cool consequence of everything being in one binary. But almost every other 
utility
set doesn't have it because most aren't multi-call binaries.

- Oliver Webb aquahobby...@proton.me

___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


Re: [Toybox] [PATCH] xxd: -d Decimal Lables flag, Don't cap at one file

2024-04-22 Thread enh via Toybox
On Sat, Apr 20, 2024 at 7:38 PM Oliver Webb via Toybox
 wrote:
>
> Looking at xxd, I noticed that the -b[inary] flag wasn't there,
> Having some facility to print binary is nice, but since printf
> doesn't have anything in built for it implementing it isn't hard,
> but it looks _ugly_. Which is why I decided not to do that in this
> patch.
>
> xxd also runs on average about 5 times slower than vim xxd, this is
> because of read reading 16 bytes at a time, also not hard to fix, but
> very hard to fix cleanly.

really? a quick glance suggests it reads blocks of sizeof(toybuf)? (or
"whatever stdio is using for its buffer" in the -r case.)

> xxd has a -d flag to do decimal address lables that I added in this patch.

do you have a _use_ for that? i saw it and ignored it when
implementing toybox xxd because i couldn't even imagine a use for
decimal addresses...

> Toybox xxd intentionally caps itself at 1 file per invocation, "Why?": Vim 
> xxd is
> a bloated pile of garbage with things like EBCDIC support. They added a
> "improvement" where if you gave 2 files to it, it would rewrite the contents
> of the second with the output of the first because it was made for operating
> systems where file redirection wasn't a built in thing. As someone who's lost
> data because of this, I'm glad there isn't support for this in toybox xxd.
>
> But even though we do loopfiles() over the arguments, There isn't any actual 
> way
> to take advantage of that code since we cap it at one file. Removing the cap 
> doesn't
> break anything that wouldn't already be broken, so I removed the ">1" in the 
> option
> string in this patch.
>
> -   Oliver Webb 
>
> P.S. As someone who once did a cleanup pass on a vim xxd fork a while back,
> a reason to not do colorized output is that you are outputting ANSI codes
> for _every byte, twice_. And unless you have code to optimize that down, your
> files can take 3/4 times longer to print out via colorized xxd since every
> line goes from 68 bytes to 420:
>
> Colored xxd:
> 0001d590: 306d 201b 5b31 3b33 376d 3030 1b5b 306d  0m .[1;37m00.[0m
> 0001d5a0: 1b5b 313b 3337 6d30 301b 5b30 6d20 1b5b  .[1;37m00.[0m .[
> 0001d5b0: 313b 3337 6d30 301b 5b30 6d1b 5b31 3b33  1;37m00.[0m.[1;3
> Normal xxd:
> 000159a0: 3030 2030 3030 3020 3030 3030 2030 3030  00   000
> 000159b0: 3020 3030 3030 2030 3030 3020 3030 3030  0   
> 000159c0: 2030 3030 3020 202e 2e2e 2e2e 2e2e 2e2e     .
> ___
> Toybox mailing list
> Toybox@lists.landley.net
> http://lists.landley.net/listinfo.cgi/toybox-landley.net
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net