bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[no subject]


From: john doe
Date: Sat, 04 Apr 2020 08:44:23 +0300

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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]