473,657 Members | 2,499 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 1224
pe**********@gm ail.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**********@gm ail.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**********@gm ail.com wrote:
Hi Rob,

Thanks for the info

RobG wrote:
pe**********@gm ail.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
1505
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 candidate for the indexing. Below is the details I want to understand: Area ZIP
2
5093
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 connected with the swap space of Operating System. Those Java utilize both memory and swap space for purpose of its heap? TIA,
28
2545
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, increment the internal value, and then return the temporary. Prefix operators (++i) increment the value and return a reference to it. With objects such as iterators, creating temporary copies is expensive compared to built-in ints.”
2
2676
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 across some wierd loop behavior. With the pasted code I receive the output that follows. I realize that the code is broken, because the inner loop fails to reset j for each iteration of the outer loop (the fix is commented out). I also know that...
10
1529
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 The trace info shows that output was done within 1 second and then i guess it took so much time (> 1 minute) for it to actually be transferred to IE. I am doing test on the same machine. IIS and IE are on the same machine and I believe the actual...
2
1053
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 functions. How can I do that? Thank you! James
19
7185
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 function for name_id obj.
2
1246
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 integer for the word. Currently this is done by filling up a std::map<wstring, int> with all words and doing an: iterator it = my_map.find(wchar_t* value) and return it->second if found, otherwise return 0. Now this routine takes pretty much time...
2
1150
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
1189
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 At time 2000 to 3000 user are using How can i improve my application perfomance, Give me tips
0
8310
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8732
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8605
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7333
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6167
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4158
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2731
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1620
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.