I'm working on a command to benchmark different formats in Bash. So far I've come up with this:
Code:
#!/bin/bash
for a in 100
do
for b in "bzip2" "lzma" "gzip"
do
dd if=/dev/zero of=$a.$b.zero bs=${a}M count=1
{time $b $a.$b.zero > $a.$b} | sed "s|.* [0-9\.]*s user [0-9\.]*s system [0-9]*% cpu \([0-9\.]*\) total|\1|" >> benchmark
echo -n "," >> benchmark
done
echo >> benchmark
done
But the sed command only pipes on the compression command, not the time command itself.
I was told on another forum to use 2>&2 and capture the stderr not the stdout. But it doesn't work. For instance:
Code:
{ time ls; } 2>&2 | sed "s/.*/1/"
Returns a 1 for every file in the directory, not one time for the time command itself.