473,397 Members | 1,960 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Use of max()?

Thekid
145 100+
I'm trying to capture the fastest time in a program. I'll use this as an example:
run and time a loop and then print out the fastest time. How do I go about that? Something like this:

Expand|Select|Wrap|Line Numbers
  1. from time import time
  2. for i in range(10):
  3.     startTime=time()
  4.     t=time()-startTime
  5.     if t>max():
  6.          max()=t
  7.          print i,t
  8.  
I know this isn't correct but used it as an example for what I'm trying to do.
Feb 22 '07 #1
5 1141
bartonc
6,596 Expert 4TB
I'm trying to capture the fastest time in a program. I'll use this as an example:
run and time a loop and then print out the fastest time. How do I go about that? Something like this:

Expand|Select|Wrap|Line Numbers
  1. from time import time
  2. for i in range(10):
  3.     startTime=time()
  4.     t=time()-startTime
  5.     if t>max():
  6.          max()=t
  7.          print i,t
  8.  
I know this isn't correct but used it as an example for what I'm trying to do.
First: here's how max() works:
>>> a = 3
>>> b = 7
>>> max(a, b)
7
>>> max(b, a)
7
>>>
Second: there are a few things wrong with what you have written:
Expand|Select|Wrap|Line Numbers
  1.          max()=t
1) You can't assign to a funcion.

Expand|Select|Wrap|Line Numbers
  1. from time import time
  2. maxDuration = 0
  3. for i in range(10):
  4.     startTime = time()
  5.     # do something that takes time
  6.     t = time() - startTime
  7.     if t > maxDuration :
  8.         maxDuration  = t
  9.         print i, t
  10.  
2) Don't you just want another variable?
3) Python has a timeit module to do all this for you. I'll dig up some info for you.
Feb 22 '07 #2
Thekid
145 100+
Thanks! I tried your script and it works nicely. I will check out timeit as well!
Feb 22 '07 #3
bartonc
6,596 Expert 4TB
Thanks! I tried your script and it works nicely. I will check out timeit as well!
The documentation is kind of lacking on this one.
Here is a link to some code snippets that I wrote. Try it out and post here (in a new thread) with questions.
Feb 22 '07 #4
Thekid
145 100+
Awesome! Thanks again!
Feb 22 '07 #5
bartonc
6,596 Expert 4TB
Awesome! Thanks again!
You are welcome. Keep posting,
Barton
Feb 22 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Steven Bethard | last post by:
So I've been playing around with trying to add a keyword argument to min and max that works similarly to the one for sorted. It wasn't too hard actually, but it does raise a few questions about...
2
by: Jack | last post by:
Greetings folks, Just curious if anyone knows what the following would produce: SELECT MAX( ECP_SUPPORT_DED_EMAIL.CD_TYP_CMPGN) CD_TYP_CMPGN, MAX(ECP_SUPPORT_DED_EMAIL.CELL_ID) CELL_ID,...
2
by: Pink Panther | last post by:
Using the following SQL can the results be explained? Using A97 (with the SP2 for Jet 3.5) or A2002 CREATE TABLE Test (PK Number CONSTRAINT PK_TEST PRIMARY KEY, ParentID Number, Child...
3
by: Ker | last post by:
I have a query that works great. It gives me the min for multiple fields. Within this query, I also need to get the max of some fields too. I currently have output of Date Name ...
8
by: charles.amith | last post by:
I have 2 tables: LOCATION and ELEVATION In location, I would like to find the record with the max value for field: DATE1 In elevation, I would like to find the record with the max value for...
61
by: norb1 | last post by:
After tracking down a bug in my Fortran program, I found that it assumed max(NaN,0.) = 0. This makes no sense, as the outcome of the operation is undefined and should be NaN. max(NaN,0.) = NaN...
19
by: Eugeny Myunster | last post by:
I know, only simple one: #include <stdio.h> int main() { int min=0,max=0,i,arr; for(i=0;i<12;i++) arr=rand()%31-10; for(i=0;i<12;i++)
54
by: bearophileHUGS | last post by:
Empty Python lists don't know the type of the items it will contain, so this sounds strange: 0 Because that may be an empty sequence of someobject: 0 In a statically typed language in...
0
by: hong.niu4 | last post by:
please look our website ,have more mode shoes clothing hat cap bags ! Air Max Air Max 87 shoes www.shoestrade.biz Air Max 90 shoes www.shoestrade.biz Air Max 91 shoes www.shoestrade.biz Air...
6
by: rahulsengupta895 | last post by:
. #define MIN(a,b) (a<b?a:b) #define MAX(a,b) (a>b?a:b) #include "Video.h" #define NO_HUE -1
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.