I had an idea to quickly benchmark some decompression programs. E.g. for gz, I would run the command:
timeout 10 zcat foo.gz | wc -c
Which would measure the amount of data the decompressor could extract in 10 seconds.
The only problem is, that it does not work: as zcat is killed, wc is also killed, so I do not get the byte count, just a
So, the question is: is there a way to get the count from wc, either by blocking the signal somehow, or use an alternative instead of wc that prints a result even when it gets a term signal.
Of course, there are alternatives:
Writing to a temporary file:
timeout 10 zcat foo.gz > /dev/shm/x ; du -sb /dev/shm/x ; rm -r /dev/shm/xThe problem with this is that is uses a lot of memory, and also may have some performance penalty.
Using ulimit instead:
ulimit -t 10; zcat foo.gz | wc -c
This also works, but measures only cpu time, so slowdown due to I/O (e.g. because the compression is worse, and more bytes need to be read from disk) is not measured.
Making smaller test files:
Well, this can work of course, and may be the nicest solution. However, this creates a lot of temporary files.