5 Replies - 867 Views - Last Post: 31 March 2012 - 05:43 PM Rate Topic: -----

#1 rpp  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 30-March 12

calculate time for execution of statement in python?

Posted 30 March 2012 - 11:55 AM

I am creating a gui using wxpython.In that m calling a definition from another class by creating instance of the class n then calling the required definition .So now want to calculate the time required for execution of that definition and show the progress using wx.gauge.My problem is how to calculate the required time n show it using progress bar?
Is This A Good Question/Topic? 0
  • +

Replies To: calculate time for execution of statement in python?

#2 Simown  Icon User is offline

  • Blue Sprat
  • member icon

Reputation: 315
  • View blog
  • Posts: 650
  • Joined: 20-May 10

Re: calculate time for execution of statement in python?

Posted 30 March 2012 - 01:25 PM

To time a statement easily, you probably want to use the time module:

import time
start = time.time()
x = pow(2, 100000)
end = time.time()
print "The assignment took", end-start, "seconds."
...
The assignment took 0.00107097625732 seconds.



I am not familiar with wxpython, can you provide the syntax for the wx.gauge or perhaps you have enough to go on now :)

This post has been edited by Simown: 31 March 2012 - 02:18 AM

Was This Post Helpful? 1
  • +
  • -

#3 rpp  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 30-March 12

Re: calculate time for execution of statement in python?

Posted 31 March 2012 - 12:53 AM

the solution given by you is right but not the complete.
using your solution I am able to calculate the time required for execution of the code but I want to show the progress of the execution.
Solution given by you gives time after the completion of code .
we can set the value to gauge using gauge.SetValue(self.count) but for that I need to get the total time before execution and also the current time so that using some calculations I can show it in gauge
Was This Post Helpful? 0
  • +
  • -

#4 Simown  Icon User is offline

  • Blue Sprat
  • member icon

Reputation: 315
  • View blog
  • Posts: 650
  • Joined: 20-May 10

Re: calculate time for execution of statement in python?

Posted 31 March 2012 - 02:17 AM

How exactly do you think you'll show a gauge for a fraction of 0.00107097625732 seconds for example, which is a reasonably big statement to evaluate? A human eye could barely even respond to the changing gauge in that time.

Maybe I'm missing something, you want the progress of a single statement to be shown on the gauge or a series of statements? A single statement like that is probably the smallest snippet of code you'll be able to time. You could manually divide that in to portions if you like.
Was This Post Helpful? 0
  • +
  • -

#5 rpp  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 30-March 12

Re: calculate time for execution of statement in python?

Posted 31 March 2012 - 03:47 AM

my all code is written in another file. I am executing that code by calling definition in another file by


converter = Converter.Converter()
converter.convert_nu_to_u()

It takes time more than 10 sec or maybe in min depending on input size to execute that code hence want to show the
progress to user
Was This Post Helpful? 0
  • +
  • -

#6 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 734
  • View blog
  • Posts: 1,890
  • Joined: 23-December 08

Re: calculate time for execution of statement in python?

Posted 31 March 2012 - 05:43 PM

So you want a way for your program to predict how long execution will take? That's not possible. However, you could create a progress bar, and update it as your code executes. Perhaps studying threading and learning about how progress meters work will help you get further in this.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1