tags:

views:

295

answers:

2

I would like to time how long it takes to submit a batch of files to an HTTP server running on localhost using Curl and write that to a file. I am having trouble getting the syntax correct.

export TIMEFORMAT="%R"
time -ao times.dat ( curl -v -d @1.batch -X POST $DB )

How can I accomplish this? I imagine it's just a matter of using the shell syntax.

A: 

time is not perfect for logging the duration.

But you can do something like:

date >> $LOGFILE
# your operation here
date >> $LOGFILE

If you want to monitor per file statistics, then you can always wrap your curl in a for loop.

Zsolt Botykai
Why is it not perfect? 'time' does the duration math for you. Your answer leaves the math as an "exercise for the reader".
Dennis Williamson
Actually it had lied to me several times under cygwin.
Zsolt Botykai
That may be a problem with Cygwin, its installation or its configuration, not necessarily a problem with `time` (unless it has a bad implementation of it - I would compare the output/accuracy of Bash's `time` versus `/usr/bin/time` to see if the problem is the same, Cygwin's "fault", or different, the "fault" of one or the other `time`).
Dennis Williamson
+4  A: 

Specify the full path to time (the parentheses are unnecessary):

export TIME="%e"
/usr/bin/time -ao times.dat curl -v -d @1.batch -X POST $DB

Note that a different environment variable and a different specifier are used to obtain the elapsed time.

time is a Bash keyword and doesn't support the options -a or -o.

/usr/bin/time is an external binary which does.

$ type -a time
time is a shell keyword
time is /usr/bin/time
$ help time
time: time [-p] PIPELINE
    Execute PIPELINE and print a summary of the real time, user CPU time,
    and system CPU time spent executing PIPELINE when it terminates.
    The return status is the return status of PIPELINE.  The `-p' option
    prints the timing summary in a slightly different format.  This uses
    the value of the TIMEFORMAT variable as the output format.
$ man time
TIME(1)                                                                TIME(1)

NAME
       time - run programs and summarize system resource usage

SYNOPSIS
       time   [ -apqvV ] [ -f FORMAT ] [ -o FILE ]
              [ --append ] [ --verbose ] [ --quiet ] [ --portability ]
              [ --format=FORMAT ] [ --output=FILE ] [ --version ]
              [ --help ] COMMAND [ ARGS ]

DESCRIPTION
       time  run  the  program  COMMAND with any given arguments ARG....  When
       COMMAND finishes, time displays information  about  resources  used  by
       COMMAND  (on  the standard error output, by default).  If COMMAND exits
       with non-zero status, time displays a warning message and the exit sta‐
       tus.
       .
       .
       .
Dennis Williamson
Indeed, /usr/bin/time not time. I thought I was losing my mind!
Ryan Rosario