[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re:
From: |
Wolfgang Laun |
Subject: |
Re: |
Date: |
Sat, 4 Apr 2020 13:14:34 +0200 |
Did it occur to you that option 2 does not only run /bin/cat (which it
hopefully really does) but, in addition to cat and gawk, also shell process
which does a lot of work up front that has already been done when option 1
really kicks off with its two processes.
-W
On Sat, 4 Apr 2020 at 12:40, john doe <address@hidden> wrote:
> Hi!
>
>
> I've just noticed that using `getline` to process a system command from
> within the script is a bit slower than piping the same command to the awk
> script. Consider these two examples:
>
> option 1:
>
> #!/bin/bash
> cat $HOME/.vim/spell/en.dic | gawk '{print}'
>
>
> option 2:
>
> #!/usr/local/bin/gawk -f
> BEGIN {
> while ("cat $HOME/.vim/spell/en.dic" | getline) {
> print
> }
> }
>
>
> When tested (with hyperfine: https://github.com/sharkdp/hyperfine), I get
> the following results:
>
> option 1:
>
> Time (mean ± σ): 88.5 ms ± 17.6 ms [User: 68.8 ms, System: 12.3
> ms]
> Range (min … max): 79.2 ms … 155.5 ms 30 runs
>
> option 2:
>
> Time (mean ± σ): 110.1 ms ± 6.7 ms [User: 93.1 ms, System: 11.3
> ms]
> Range (min … max): 104.0 ms … 128.1 ms 30 runs
>
> This is probably not a bug, since the gap stays when using other awk
> interpreters, too, like BSD awk, or mawk, but still, I wonder, if it's
> possible somehow to minimize it?
>
> Would be grateful for any advice,
>
>
> Thank you.
>
>
> --
> JD
>
>
- [no subject], john doe, 2020/04/04
- Re:,
Wolfgang Laun <=
- Re: (No subject), john doe, 2020/04/04
- Re: (No subject), Davide Brini, 2020/04/04
- Re: (No subject), john doe, 2020/04/04
- Re: (No subject), Wolfgang Laun, 2020/04/04
- Message not available
- Re: (No subject), john doe, 2020/04/04
- Re: (No subject), Wolfgang Laun, 2020/04/04
- Re: (No subject), john doe, 2020/04/04
- Re: (No subject), Davide Brini, 2020/04/04
- Re: (No subject), john doe, 2020/04/04
- Re: (No subject), Wolfgang Laun, 2020/04/04