473,505 Members | 13,807 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

loop perfomance: for vs. for-in?

Hi,

Is there a general consenses which is faster?

a) a for loop to iterate through n objects stored in an array
b) a for-in loop to iterate through n objects stored as properties of
an object

I'm deciding which storage technique I should use for targets in a
dragdrop application. When I move the dragging object I must loop
through the possible targets to determine which targets the dragging
object is over. Since this must happen with every mouse move I'd like
to make this efficient.

Thanks,
Peter

Jun 13 '06 #1
3 1211
pe**********@gmail.com wrote:
Hi,

Is there a general consenses which is faster?

a) a for loop to iterate through n objects stored in an array
b) a for-in loop to iterate through n objects stored as properties of
an object
Test it and see - there are also do..while and while loops. You may
chose to use an array of objects, where each object has a reference to
an element and its bounding coordinates. You can use for..in with an
Array too (it's a JavaScript Object too) provided you deal with any
other enumerable properties you may have added.

However, be careful of premature optimisation - you may be searching
for fractions of a millisecond with loops but missing much greater
optimisations elsewhere.

I'm deciding which storage technique I should use for targets in a
dragdrop application. When I move the dragging object I must loop
through the possible targets to determine which targets the dragging
object is over. Since this must happen with every mouse move I'd like
to make this efficient.


It probably doesn't matter. If your drop zones don't overlap, have you
considered using a mouseover on the drop zones so they report "hey,
you're over me"?

--
Rob

Jun 13 '06 #2
Hi Rob,

Thanks for the info

RobG wrote:
pe**********@gmail.com wrote:
It probably doesn't matter. If your drop zones don't overlap, have you
considered using a mouseover on the drop zones so they report "hey,
you're over me"?


My drop zones may overlap. However if they did not I haven't found a
way to do the mouseover listing because the draggable item is always
directly under the cursor. So the target never registers a mouse over.
Is there a new trick for this? Most libraries have to loop through the
targets for each mousemove to examine the region of each target and the
cursor position. It is slow.

Peter

Jun 13 '06 #3

pe**********@gmail.com wrote:
Hi Rob,

Thanks for the info

RobG wrote:
pe**********@gmail.com wrote:
It probably doesn't matter. If your drop zones don't overlap, have you
considered using a mouseover on the drop zones so they report "hey,
you're over me"?


My drop zones may overlap. However if they did not I haven't found a
way to do the mouseover listing because the draggable item is always
directly under the cursor. So the target never registers a mouse over.
Is there a new trick for this? Most libraries have to loop through the
targets for each mousemove to examine the region of each target and the
cursor position. It is slow.

Peter


I saw a trick in the book 'DHTML Utopia' which you might be able to
use. The author suggests having an extra parallel layer of invisible
(transparent) elements above the layer with the draggable object in.
Each invisible object is above one of the real drag targets, so you can
use an onmouseover event on it.

Jun 13 '06 #4

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

Similar topics

5
1500
by: SuryaPrakash Patel via SQLMonster.com | last post by:
Dear Reader I am trying to design a database. How can I make best Judgement that Indexing (which I am trying to fix during Diagram Desingning process)is ok. I am able to identify the best...
2
5085
by: news.onet.pl | last post by:
I've launched some perfomance test for some program measuring number of operations, net messages processed per second, etc. Why is my point, is the question how Java initial and maximal heap is...
28
2520
by: Papadopoulos Giannis | last post by:
a) pre vs post increment/decrement I have read somewhere that: “Prefer pre-increment and -decrement to postfix operators. Postfix operators (i++) copy the existing value to a temporary object,...
2
2658
by: Alex | last post by:
Compiler - Borland C++ 5.6.4 for Win32 Copyright (c) 1993, 2002 Borland Linker - Turbo Incremental Link 5.65 Copyright (c) 1997-2002 Borland Platform - Win32 (XP) Quite by accident I stumbled...
10
1517
by: George | last post by:
Hi, I have a report which shows all records from database into the browser. The final HTML comes out about 5 Meg. It takes 1 minute 5 seconds for transfer to show up when i hit the page with IE...
2
1045
by: James T. | last post by:
Hello! Let's say I have 2 functions, both return data from the database. Now I would like to compare perfomance of these two functions. I would like to know how long it takes to execute these...
19
7128
by: Krishanu Debnath | last post by:
Hello, I have a call to hash_map::clear() function which takes long time. someClass::someFunction() { // typedef hash_map<name_id, uintMp; // Mp p; // assuming proper namespace, hash...
2
1236
by: Alexander Adam | last post by:
Hi, What I am having is this -- I got a string start (type is wchar_t) and the end of a string to compare. Now I've got around 500 words to compare to and if matched, I want to get an unique...
2
1136
by: MickJ | last post by:
Hi, I would like to write High perfomance server using C#. It would be desirable to hear offers and advices on this subject.
0
1175
by: ferozanna | last post by:
I am using Asp.net 1.3 with C# My application used by call center people My applicaton is a three tier arch I have create data layer as class ibrary which goint to talke Ssqlserver 205 db ...
0
7213
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7298
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
7471
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
5610
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,...
1
5026
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...
0
4698
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
754
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
406
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.