Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm writing a program that performs certain optimizations on an executable file and am looking for a way to measure the time the executable took to run.

I've been using a script that measures the start time and end time, but this doesn't take into account that the process might not be running all the time (due to OS resource allocation).

Will the PowerShell command 'Measure-Command' give me a more precise response? And will 'Time' do the same on Linux?

If not, how should I go about doing so? (A command line solution is preferable.)

share|improve this question
    
I don't know if it can be done outside of the program itself. What language is the program being written in? –  Scott Chamberlain Aug 25 '13 at 13:51
    
@ScottChamberlain Java. I looked it up, but it seems that I can only accomplish this through java if I set it up in an outside environment (Like Google Caliper), and only for benchmarking purposes, while I need it for my program behavior. –  Yonadav Schleifer Aug 25 '13 at 16:12

2 Answers 2

up vote 0 down vote accepted

I can't speak as to the Windows command, but yes, the *nix time will give you a more precise response:

$ time du -sch /usr/local/
147M  /usr/local/
147M  total

real    0m2.977s
user    0m0.008s
sys     0m0.076s

According to man time it can display (among many other things):

    E      Elapsed real (wall clock) time used by
           the process, in
           [hours:]minutes:seconds.
    P      Percentage of the CPU that this job
           got.  This is just user + system times
           divided by the total running time.  It
           also prints a percentage sign.
    S      Total number of CPU-seconds used by the
           system on behalf of the process (in
           kernel mode), in seconds.
    U      Total number of CPU-seconds that the
           process used directly (in user mode),
           in seconds.
    e      Elapsed real (wall clock) time used by
           the process, in seconds.
share|improve this answer

In PowerShell, you can use Get-Process:

Get-Process | select starttime
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.