[Tutor] simple random string generator

Matthew Dalrymple computer_dude15 at hotmail.com
Tue Sep 18 06:22:14 CEST 2012


> Look at what your timing code does:
> 
> start = time.time()
> for i in range(10000):
>      anagramSolution2(word,word)
>      end1 = time.time()
>      solu2 = end1 - start
> 
> 
> Translated into English:
> 
> * start the timer
> * iteration 1 begins
> * call the anagram function
> * grab the ending time
> * calculate the difference in time
> * iteration 2 begins
> * call the anagram function
> * grab the ending time
> * calculate the difference in time
> * iteration 3 begins
> * call the anagram function
> * grab the ending time
> * calculate the difference in time
> ... and so on ...
> * iteration 10000 begins
> * call the anagram function
> * grab the ending time
> * calculate the difference in time
> 
> and finally you are done. Do you see what you have done? You calculate
> the time difference 10000 times instead of once. What you want is:
> 
> * start the timer
> * iteration 1 begins
> * call the anagram function
> * iteration 2 begins
> * call the anagram function
> * iteration 3 begins
> * call the anagram function
> ... and so on ...
> * iteration 10000 begins
> * call the anagram function
> * grab the ending time
> * calculate the difference in time
> 
> You should calculate the difference in time ONCE, not 10000 times. so what should be done then would be to make sure that the start and end time are like this? for n in range(10, 101, 5):    word = mkword(n)    start = time.time()    for i in range(10000):        anagramSolutionX(word,word,    end1 = time.time()    solu2 = end1 - start is that right?sorry if im making this harder than it should be to me that would make sense because you would be asking it to do it 10000 times before it would move on to the end time? thanks again for all the help guysit means a lot 
> 
> 
> > to me it looks like it should be right but the one line i think
> >is supposed to increas exponentially
> 
> I'm not sure why you think that. I'm not saying that it shouldn't,
> but I honestly can't tell. The code is so convoluted that I'm not
> sure what it does without detailed study, but at a quick glance I
> can't see anything that would make one of the anagram functions
> take O(N**2) time.
> 
> 
> 
> -- 
> Steven
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120918/c8f75f11/attachment-0001.html>


More information about the Tutor mailing list