Register
It is currently Tue Jul 29, 2014 8:58 pm

Benchmarking in Bash


All times are UTC - 6 hours


Post new topic Reply to topic  [ 3 posts ] 
Author Message
 PostPosted: Sun Oct 18, 2009 2:35 pm   

Joined: Sun Oct 18, 2009 2:27 pm
Posts: 2
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.


Top
 Profile  
 PostPosted: Mon Oct 19, 2009 2:35 am   

Joined: Mon Nov 17, 2008 7:25 am
Posts: 221
If you're using GNU extended "date" then this might be an aproach
Code:
for a in 100
do
  for b in "bzip2" "lzma" "gzip"
  do
    start=$(date +%s)
    outp=$(dd if=/dev/zero of=$a.$b.zero bs=${a}M count=1)
    stop=$(date +%s)
    total=$(echo "$stop - $start" | bc)
    echo "Took $total seconds to finish" >> output.log
  done
done


That seems like a wierd version of redirecting stderr...

This is the usual version to redirect proper stderr.
Code:
# cat /file/that/does/not/exist 2> stderr.log


This however requires that the programmer of that specific software actually used stderr. This is sadly not always the case.

Best regards
Fredrik Eriksson


Top
 Profile  
 PostPosted: Mon Oct 19, 2009 3:40 pm   

Joined: Sun Oct 18, 2009 2:27 pm
Posts: 2
Good idea, that seems to have worked.


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP