473,394 Members | 1,761 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,394 software developers and data experts.

Re: Interesting timing issue I noticed

En Wed, 16 Apr 2008 10:36:14 -0300, Jonathan Shao <jz*****@gmail.com>
escribió:
*Gabriel Genellina* gagsl-py2 at yahoo.com.ar
<python-list%40python.org?Subject=Interesting%20timing%20i ssue%20I%20noticed&In-Reply-To=>
*Wed Apr 16 08:44:10 CEST 2008*
>Another thing would be to rearrange the loops so the outer one executes
less times; if you know that borderX<<sizeX and borderY<<sizeY it may be
better to swap the inner and outer loops above.
Thank you for the tip on xrange.
Even if I swap the inner and outer loops, I would still be doing the same
number of computations, am I right (since I still need to go through the
same number of elements)? I'm not seeing how a loop swap would lead to
fewer
computations, since I still need to calculate the outer rim of elements
in
the array (defined by borderX and borderY).
You minimize the number of "for" statements executed, and the number of
xrange objects created. Both take some time in Python.

<code>
import timeit

f1 = """
for i in xrange(10):
for j in xrange(1000):
i,j
"""

f2 = """
for j in xrange(1000):
for i in xrange(10):
i,j
"""

print timeit.Timer(f1).repeat(number=1000)
print timeit.Timer(f2).repeat(number=1000)
</code>

Output:
[2.0405478908632233, 2.041863979919242, 2.0397852240997167]
[2.8623411634718821, 2.8330055914927783, 2.8361752680857535]

The second (using the largest outer loop) is almost 40% slower than the
first one. "Simplified" Big-Oh complexity analysis isn't enough in cases
like this.

--
Gabriel Genellina

Jun 27 '08 #1
0 552

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Russell | last post by:
I have a quirky issue that I believe involves timing and only 2 hairs left to pull. I have a modal dialog that is an IFrame. The IFrame contains another window - which contains the appropriate...
3
by: pbbriggs | last post by:
I will try to be as descriptive as possible, but this error has me stumped and I am not sure what relevant info to include.... I am running Access XP on a Windows XP machine. I initially began...
7
by: Jacob Barnett | last post by:
Access 2000 main report does not display subreport data in preview and may or may not print... sometimes. Usually, the entire report is fine. The behavior does not seem to depend on particular...
4
by: Brian Hanson | last post by:
Hi, I have a problem that is sporadic and am thinking it may come down to a timing issue. I have an asp.net (vb) app that used the system.io.file.copy method to copy a .pdf file from a network...
5
by: Richard Charts | last post by:
I am building a simulator that needs to send out 2 messages on a tcp connection each at a rate of 1 packet / 50ms. Right now it kind of works in that it is sending 8 (4 of each) at 200ms. Is...
27
by: Frederick Gotham | last post by:
I thought it might be interesting to share experiences of tracking down a subtle or mysterious bug. I myself haven't much experience with tracking down bugs, but there's one in particular which...
4
by: Nebulus | last post by:
We've got a website that's designed in classic ASP. While it's a good product, the original design was badly done, and I've inherited a monster. At some point last week, users began calling in...
2
by: julie.siebel | last post by:
Google apparently ate my original post to this (grr) so this'll be a bit more vague than the initial post, but...*sigh*. Javascript is not my forte, and I apologize for the acky-ness of the...
2
by: Jay | last post by:
Getting into AJAX using the XMLHttp object and am really liking it. We are in the process of upgrading our existing behavior calls (webservice.htc) to the more 'supported', as they say, concept...
0
by: Daniel Fetchinson | last post by:
On 4/15/08, Daniel Fetchinson <fetchinson@googlemail.comwrote: BTW, using the following ###################################################################### # CODE TO TEST BOTH...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...

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.