Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getline is much slower when reading from a pipe or redirected file compared with mawk. #4

Open
ghuls opened this issue Sep 24, 2024 · 0 comments
Assignees

Comments

@ghuls
Copy link

ghuls commented Sep 24, 2024

As frawk development has stalled for the moment, you might have some time to investigate the relative slowness of getline when reading from a pipe (eg. "cat - " | or a redirected file (e.g < "/dev/stdin").

ezrosent#98 (comment)

Also zawk is slower than frawk (but this might be due the fact that I didn't manage to build it with unstable feature yet.

# Read and print all input lines.
$ time yes | head -n 100000000 | mawk '{ print $0 }' > /dev/null

real    0m4.562s
user    0m4.472s
sys     0m0.300s

$ time yes | head -n 100000000 | frawk '{ print $0 }' > /dev/null

real    0m8.485s
user    0m8.544s
sys     0m0.292s

$ time yes | head -n 100000000 | /software/zawk/target/release/zawk '{ print $0 }' > /dev/null                                                                  

real    0m13.969s
user    0m14.031s
sys     0m0.291s


$ time yes | head -n 100000000 | mawk 'BEGIN { while ( (getline ) > 0 ) { print $0 } }' > /dev/null

real    0m7.293s
user    0m7.143s
sys     0m0.309s

$ time yes | head -n 100000000 | frawk 'BEGIN { while ( (getline ) > 0 ) { print $0 } }' > /dev/null

real    0m7.279s
user    0m7.351s
sys     0m0.288s

$ time yes | head -n 100000000 | /software/zawk/target/release/zawk 'BEGIN { while ( (getline ) > 0 ) { print $0 } }' > /dev/null                               

real    0m11.796s
user    0m11.818s
sys     0m0.311s


# Count number of input lines:
$ time yes | head -n 100000000 | mawk 'END { print NR }'
100000000

real    0m2.245s
user    0m2.141s
sys     0m0.276s

$ time yes | head -n 100000000 | frawk 'END { print NR }'
100000000

real    0m3.905s
user    0m3.963s
sys     0m0.272s

$ time yes | head -n 100000000 | /software/zawk/target/release/zawk 'END { print NR }'                                                                          
100000000

real    0m6.300s
user    0m6.328s
sys     0m0.295s


$ time yes | head -n 100000000 | mawk 'BEGIN { while ( (getline ) > 0 ) { line_count += 1;} print line_count}'
100000000

real    0m5.724s
user    0m5.619s
sys     0m0.290s

$ time yes | head -n 100000000 | frawk 'BEGIN { while ( (getline ) > 0 ) { line_count += 1;} print line_count}'
100000000

real    0m2.628s
user    0m2.686s
sys     0m0.267s

$ time yes | head -n 100000000 | /software/zawk/target/release/zawk 'BEGIN { while ( (getline ) > 0 ) { line_count += 1;} print line_count}'                    
100000000

real    0m4.128s
user    0m4.186s
sys     0m0.265s


$ time yes | head -n 100000000 | mawk 'BEGIN { while ( (getline < "/dev/stdin") > 0 ) { line_count += 1;} print line_count}'       
100000000

real    0m6.523s
user    0m6.440s
sys     0m0.265s

$ time yes | head -n 100000000 | frawk 'BEGIN { while ( (getline < "/dev/stdin") > 0 ) { line_count += 1;} print line_count}'                                                                      
100000000

real    0m20.624s
user    0m20.635s
sys     0m0.300s

$ time yes | head -n 100000000 | /software/zawk/target/release/zawk 'BEGIN { while ( (getline < "/dev/stdin") > 0 ) { line_count += 1;} print line_count}'      
100000000

real    0m29.226s
user    0m29.207s
sys     0m0.300s


$ time yes | head -n 100000000 | mawk 'BEGIN { while ( ("cat -" | getline) > 0 ) { line_count += 1;} print line_count}'            
100000000

real    0m6.426s
user    0m6.367s
sys     0m0.384s

$ time yes | head -n 100000000 | frawk 'BEGIN { while ( ("cat -" | getline) > 0 ) { line_count += 1;} print line_count}'                                                                          
100000000

real    0m20.072s
user    0m20.063s
sys     0m0.369s

$ time yes | head -n 100000000 | /software/zawk/target/release/zawk 'BEGIN { while ( ("cat -" | getline) > 0 ) { line_count += 1;} print line_count}'           
100000000

real    0m28.472s
user    0m28.406s
sys     0m0.416s

@linux-china linux-china self-assigned this Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants