Welcome Guest [Log In] [Register]
Search Members Calendar | Rules ZB Code Index IF Code Index
ZBCode
  • Navigation
  • ZBCode
  • Coding Support
  • Code University
  • Coding For Loops
Hey, welcome to ZBCode, the premier coding forum for ZB. Here you fill find some of the best Invisionfree and Zetaboards Codes on the network! Unfortunately, you're sorta hovering around in guest mode at the moment; why not join in on the fun? Register an account and you can start accessing the wealth of resources we have available here. Enjoy your stay at ZBCode, and remember to tell all your friends about us; the more members, the more codes available. ;)

Interested in joining? Click here.


If you are already a member of ZBCode, feel free to login right here:

Username:   Password:
Locked Topic
  • Pages:
  • 1
  • 2
Coding For Loops
Tweet Topic Started: Aug 15 2008, 07:24 AM (914 Views)
Ryura Aug 21 2008, 07:35 PM Post #11
Member Avatar


Posts:
38
Group:
Member
Member
#11
Joined:
Jul 8, 2008
Coding language
Ruby on Rails
Zefer
Aug 21 2008, 09:30 AM
Code:
 

a=document.getElementsByTagName("div")
for(i in a)
{
// Code Here
};

That's how I do it.
That's actually the slowest method you can do. for (var in obj) should only be used for objects - it actually has to check keys/vals while using the arr.length property is much quicker, especially when cached.
Offline Profile Goto Top
 
Zoopey Aug 22 2008, 10:44 AM Post #12
Member Avatar
Can anyone else hear the music?

Posts:
268
Group:
Admins
Member
#1
Joined:
Jun 8, 2008
Coding language
Everything
I think it's admirable people are thinking about their codes' execution times, but I feel that the current problem inhibitions our society computer-wise is not everyone's average processor speed but everyone's average internet connection; thus what probably should be focused on is load times, not execution times.

That's why I worry more about the shortest way to code something rather than the way to make it run fastest. I have been told my prorities are screwed up though, especially after I started wondering whether or not I had left my goldfish enough food when my parents were looking for their lost boarding cards and passports in a foreign country.

*wonders*
♬ Come sail away, come sail away, come sail away with me! ♬-Styx[ustyle][prefix=][suffix=][/ustyle]
Offline Profile Goto Top
 
Ryura Aug 22 2008, 08:19 PM Post #13
Member Avatar


Posts:
38
Group:
Member
Member
#11
Joined:
Jul 8, 2008
Coding language
Ruby on Rails
Choco
Aug 22 2008, 10:44 AM
I think it's admirable people are thinking about their codes' execution times, but I feel that the current problem inhibitions our society computer-wise is not everyone's average processor speed but everyone's average internet connection; thus what probably should be focused on is load times, not execution times.

That's why I worry more about the shortest way to code something rather than the way to make it run fastest. I have been told my prorities are screwed up though, especially after I started wondering whether or not I had left my goldfish enough food when my parents were looking for their lost boarding cards and passports in a foreign country.

*wonders*
With the small size of most JS files and caching, as well as faster internet connections, load speed is no longer too much of an issue.

Believe me, when you're trying to make an event that loops through 1000's of DOM - or even object - elements, good looping matters. Users with slow connections expect pages to load slow, but they do *not* expect slow response when clicking on elements of a page.
Offline Profile Goto Top
 
Zoopey Aug 23 2008, 08:55 AM Post #14
Member Avatar
Can anyone else hear the music?

Posts:
268
Group:
Admins
Member
#1
Joined:
Jun 8, 2008
Coding language
Everything
Ryura
Aug 22 2008, 08:19 PM
Choco
Aug 22 2008, 10:44 AM
I think it's admirable people are thinking about their codes' execution times, but I feel that the current problem inhibitions our society computer-wise is not everyone's average processor speed but everyone's average internet connection; thus what probably should be focused on is load times, not execution times.

That's why I worry more about the shortest way to code something rather than the way to make it run fastest. I have been told my prorities are screwed up though, especially after I started wondering whether or not I had left my goldfish enough food when my parents were looking for their lost boarding cards and passports in a foreign country.

*wonders*
With the small size of most JS files and caching, as well as faster internet connections, load speed is no longer too much of an issue.

Believe me, when you're trying to make an event that loops through 1000's of DOM - or even object - elements, good looping matters. Users with slow connections expect pages to load slow, but they do *not* expect slow response when clicking on elements of a page.
Duly noted. :D
♬ Come sail away, come sail away, come sail away with me! ♬-Styx[ustyle][prefix=][suffix=][/ustyle]
Offline Profile Goto Top
 
Eureka DC Sep 21 2008, 08:04 PM Post #15
Member Avatar


Posts:
183
Group:
Member
Member
#40
Joined:
Jul 16, 2008
Ryura
Aug 21 2008, 07:35 PM
Zefer
Aug 21 2008, 09:30 AM
Code:
 

a=document.getElementsByTagName("div")
for(i in a)
{
// Code Here
};

That's how I do it.
That's actually the slowest method you can do. for (var in obj) should only be used for objects - it actually has to check keys/vals while using the arr.length property is much quicker, especially when cached.
Though it's necessary at times, like an extend method for an Object.

Code:
 

var i = iTD.length;
while(i--){

}


That is still not the fastest way because you're making the code iterate the array to get the length before you do your cycle. It should go through the array in one cycle. Same for all the do-while loops displayed here. But in truth, they are faster than the one Webworldx started with in the original post of this topic. :P
Edited by Eureka DC, Sep 21 2008, 08:06 PM.
DO NOT PM ME FOR HELP, SUPPORT OR REQUESTS!
Posted Image
-------------------------------------------------------------------
I'm a part of you, you're a part of me
And I know it's wrong but I can't get free
You're like my first bad habit
How am I gonna give you up?
~ Vanessa Hudgens
-------------------------------------------------------------------
Offline Profile Goto Top
 
Reid Apr 18 2009, 07:13 PM Post #16
Member Avatar
What? The land of the free? Whoever told you that was your enemy.

Posts:
1,790
Group:
Distinguished Coder
Member
#148
Joined:
Jul 20, 2008
I feel this topic needs bumping, regardless of how old it is. I just did a little research and the results are astounding when you have your length cached.

The timing doesn't matter until you start adding code upon code. For example, zbcode, even though it's heavily modified, takes very little time to load, whereas I've been to some boards that take 5-6 seconds just to begin executing code thanks to all of the inefficient scripts inhabiting the place..

And, remember, some browsers ( like IE... ouch ) take a super long time just to execute code. In a single script it doesn't matter too much, but once you have 2-3 or 5-6 scripts sitting around it does really slow things down.

Also.. while a lot of the coders here do this, for any future ones - restrict codes to specific pages. For example, you shouldn't bother the user with a script that modifies how you send PMs on pages that only have topics.

I've been bad in the past about optimization but looking through a VERY detailed benchmark study lately, I just felt that this needed a bump... :P
The Resource Board
Offline Profile Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
« Previous Topic · Code University · Next Topic »
Locked Topic
  • Pages:
  • 1
  • 2

Track Topic · E-mail Topic Time: 7:48 PM Jul 10
Hosted for free by ZetaBoards · Privacy Policy