Register and join over 40,000 other developers!
Recent Topics
-
Print specific values from dictionary with a specific key name
Siten0308 - Jun 20 2019 01:43 PM
-
Learn algorithms and programming concepts
johnnylo - Apr 23 2019 07:49 AM
-
Job Gig PHP Form Needed
PJohnson - Apr 18 2019 03:55 AM
-
How to make code run differently depending on the platform it is running on?
xarzu - Apr 05 2019 09:17 AM
-
How do I set a breakpoint in an attached process in visual studio
xarzu - Apr 04 2019 11:47 AM
Recent Blog Entries
Recent Status Updates
Popular Tags
- networking
- Managed C++
- stream
- console
- database
- authentication
- Visual Basic 4 / 5 / 6
- session
- Connection
- asp.net
- import
- syntax
- hardware
- html5
- array
- mysql
- java
- php
- c++
- string
- C#
- html
- loop
- timer
- jquery
- ajax
- javascript
- programming
- android
- css
- assembly
- c
- form
- vb.net
- xml
- linked list
- login
- encryption
- pseudocode
- calculator
- sql
- python
- setup
- help
- game
- combobox
- binary
- hello world
- grid
- innerHTML

10 replies to this topic
#1
Posted 05 November 2012 - 09:58 AM
is there any difference in runtime for javascript code if i were to write for instance 100 variables manually as opposed to using a loop to write them? i mean other than the obvious time it would take to actually write them (in wich case the loop would probably be the best)
im asuming none of them are running faster or slower than the other? since they essentially do the same thing, or am i wrong?
im asuming none of them are running faster or slower than the other? since they essentially do the same thing, or am i wrong?
#2
Posted 05 November 2012 - 10:32 AM
Why would you want to manually code 100 variables rather than use a loop? Seems to me any performance difference (if any) would be infinitesimally small compared to the absolute uselessness of 100 hard-coded variables compared with, say, an array of 100 spaces.
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid
#3
Posted 05 November 2012 - 10:38 AM
100 variables, no difference...
10 000 variables, you might start to see a difference, but it's still gonna be pretty small
So insted of typing 100 or 10 000 variables manually, take that time and check your code elsewhere to look for better optimisation.
10 000 variables, you might start to see a difference, but it's still gonna be pretty small
So insted of typing 100 or 10 000 variables manually, take that time and check your code elsewhere to look for better optimisation.
You can now stalk me on linkedin: http://ca.linkedin.c...elle/24/b44/88/ !
#4
Posted 05 November 2012 - 11:34 AM
Technically, inline code is always faster than calls or looping. (The loop statement takes a finite amount of time to execute, and it has to execute once for every loop.)
Considering that many people are still running browsers with crappy Javascript interpreters (like IE6), the difference in execution time on a given computer will probably be lost in the noise. (Even IE9 can bog down with certain Javascript constructs.) If the data is such that it can be written in a loop (data1, data2, data3, etc.), do it in a loop.
Considering that many people are still running browsers with crappy Javascript interpreters (like IE6), the difference in execution time on a given computer will probably be lost in the noise. (Even IE9 can bog down with certain Javascript constructs.) If the data is such that it can be written in a loop (data1, data2, data3, etc.), do it in a loop.
#5
Posted 05 November 2012 - 04:00 PM
interesting ... if you work for yourself then do a loop ... if you work for a company then do 100 variables ... since you will get more pay
... just some thing to cheer up ... I guess you already knew the answer


www.pickmike.com
I don't just develop software. I find solutions to your business needs.
#6
Posted 05 November 2012 - 04:19 PM
That is at the exact same time, the best and the worst answerinteresting ... if you work for yourself then do a loop ... if you work for a company then do 100 variables ... since you will get more pay
... just some thing to cheer up ... I guess you already knew the answer

But you forgot to mention to not use copy/paste but to type each letter
You can now stalk me on linkedin: http://ca.linkedin.c...elle/24/b44/88/ !
#7
Posted 05 November 2012 - 09:19 PM
Technically, inline code is always faster than calls or looping. (The loop statement takes a finite amount of time to execute, and it has to execute once for every loop.)
There you got some answer, i add up that since javascript is an interpreted code, you will just have to decide which time you want to expend: parsing time (when file loading) or execution time. the diff is you can use the execution time in a iframe or after document.onload, parsing is always at first and will make the page rendering slower.
when still will look like no difference in most browsers, it might have some loading impact in no-coders, old machines, these with low hardware and full of **, you have no idea how bad an old explorer to the neck with crappy plugins looks like, lol!
#8
Posted 05 November 2012 - 11:10 PM
haha thanks for the replies guys 
as a programmer i would probably always use loops, since it saves time while writing the code. its just something i was rather curious about, and thus felt i needed to get an answer
sometimes its just fun to learn the small, more insignificant stuff about code and not just the bigger more appealing stuff. thanks again.

as a programmer i would probably always use loops, since it saves time while writing the code. its just something i was rather curious about, and thus felt i needed to get an answer

sometimes its just fun to learn the small, more insignificant stuff about code and not just the bigger more appealing stuff. thanks again.
#10
Posted 06 November 2012 - 02:55 PM
It's trivial to write a program to write a JS routine with 100,000 variables. The fun comes in when you run the web page into IE5 or 6 and grow old hitting the "continue" button 10,000 times.
#11
Posted 09 November 2012 - 02:14 AM
There is no difference but will be better to use loop for a large number of executions.
Also tagged with one or more of these keywords: loop
Language Forums →
PHP →
Content and title won't show on certain page in WordpressStarted by Mello, 05 Jan 2016 ![]() |
|
![]() |
||
Language Forums →
C# →
Create Staircase with Nested LoopsStarted by StainedSilva, 12 Mar 2015 ![]() |
|
![]() |
||
Language Forums →
Other Languages →
Bash / Shell Scripting →
Here is a task... Find Nothing :PStarted by ShaunPrawn, 07 Aug 2014 ![]() |
|
![]() |
||
General Forums →
General Programming →
Trying to do a working loopStarted by Error, 23 Jun 2014 ![]() |
|
![]() |
||
Language Forums →
PHP →
Problem in displaying data inside table formatStarted by newphpcoder, 25 Jul 2013 ![]() |
|
![]() |
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download