Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 264779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:42:50+00:00 2026-05-11T22:42:50+00:00

I would like to use python to make system calls to programs and time

  • 0

I would like to use python to make system calls to programs and time them. From the Linux command line if you type:

$ time prog args

You get something along the lines of:

real    0m0.110s
user    0m0.060s
sys     0m0.024s

if you do a ‘man time’, it states that you can type:

$ time -f "%E" prog args

in order to format to get only display the elapsed time. This does not work in the shell. I beleive it doesn’t work because bash must have its own time function. If you type:

$/usr/bin/time -f "%E" prog args

you get the expected output as stated in the man pages.

I want the bash time because it seems to be more accurate. My problem is, when you try to use the ‘time prog args’ command from python, it doesn’t behave the same way as when you type it in.

Code below to see what I’m doing (Please excuse the sloppiness):

#!/usr/bin/env python
"""Quick & Dirty script to time program execution for multiple inputs.
Saves the results as a .csv for importing into excel."""
import subprocess
timing = 'time -f "%E" '
program = 'java smartfib '
filename = 'smarttimes.csv'
#arglist = [0, 10, 20, 30, 31, 32, 33, 34, 35]
#arglist = [0, 2, 3, 5]
arglist = range(50)
timelist = list()

#run the program with the specified input values
for arg in arglist:

    cmd = timing + program + str(arg)
    pipe = subprocess.Popen(cmd, shell = True, bufsize = 256,
                stderr = subprocess.PIPE, stdout = subprocess.PIPE)

    [answer,times] = pipe.communicate() #read from pipe
    #print times
    if(int(answer) < 0):
        print "overflow occured at fib(%d)!\n" %arg
        break
    #save (n, [time it takes to complete] as a tuple in a list)
    timelist.append([arg,times])


csv = list() #list for formatted comma separated values for excel
for item in range(len(timelist)):
    csv.append(
        str(timelist[item][0]) + "," + timelist[item][1][2:].strip('\n')
        )

results = file(filename,'w')
results.write('n,time(in s)\n')
for item in range(len(csv)):
    results.write(csv[item]+'\n')

results.close()

def getTimeInSeconds(self, timestring):
    pass
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T22:42:50+00:00Added an answer on May 11, 2026 at 10:42 pm

    You are correct that bash has it’s own version of time.

    $ type time
    time is a shell keyword
    

    Perhaps you could explicitly invoke bash with the -c option to get it’s timing.

    Depending on which distribution you’re using, the default shell may be dash, a simpler shell that doesn’t have time as a keyword. Both Debian and Ubuntu use dash but I don’t know what Red Hat, Fedora and others use.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 124k
  • Answers 124k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Are you running on OS 3.0? I saw the same… May 12, 2026 at 1:19 am
  • Editorial Team
    Editorial Team added an answer It looks like you need to register Apache::Session::Memcached with Apache::Session::Wrapper,… May 12, 2026 at 1:19 am
  • Editorial Team
    Editorial Team added an answer Use DATENAME or DATEPART: SELECT DATENAME(dw,GETDATE()) -- Friday SELECT DATEPART(dw,GETDATE())… May 12, 2026 at 1:19 am

Related Questions

I haven't a clue about encryption at all. But I need it. How? Say
I'm hoping to make a quick script to log-out/restart windows at a set time.
I am writing an application where one of the features is to allow the
I am in the design phase of a file upload service that allows users
SymPy is a great tool for doing units conversions in Python: >>> from sympy.physics

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.