openSUSE Forums > Programming/Scripting » Python program execution time

Go Back   openSUSE Forums > Programming/Scripting
Forums FAQ Members List Search Today's Posts Mark Forums Read


Programming/Scripting Questions about programming, bash scripts, perl, php, cron jobs, ruby, python, etc.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 29-Aug-2009, 22:01
Student Penguin
 
Join Date: Jul 2009
Posts: 74
nipunreddevil hasn't been rated much yet
Default Python program execution time

I need to output time taken by various functions in a python program.Have not been able to find an easy enough example on using profilers.Can we use some other way without using profilers,something like clock() in Turbo C.Please give an example regarding both approches as it will be extremely helpful and will solve lots of problems for me
Code:
import time
a=time.clock()

for i in range(1,100):
	for j in range(1,100):
		print i*j
b=time.clock()
print b
print a
Code:
import time
a=time.time()

for i in range(1,100):
	for j in range(1,100):
		print i*j
b=time.time()
print b
print a
These two dont seem to me as perfect.Multiplication happens faster than addition
Reply With Quote
  #2 (permalink)  
Old 30-Aug-2009, 11:20
Monex's Avatar
Busy Penguin
 
Join Date: Jun 2008
Location: Germany
Posts: 256
Monex hasn't been rated much yet
Default Re: Python program execution time

Hi,

there are some modules that provides profiler functionality. Just have a look at 27.4. The Python Profilers — Python v2.6.2 documentation

Hope this helps
Reply With Quote
Reply

Bookmarks


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




 

Search Engine Friendly URLs by vBSEO 3.3.0 RC2