Static vs Dynamic Variables - Speed Difference

  • Thread starter Thread starter Guest
  • Start date Start date
But then you must consider that dynamic variables will allocated memory
on the heap and hence may be faster. It is very ambiguous because it
also depends on whether the variables will be Value or Reference
variables.

with regards,


J.V.Ravichandran
- http://www.geocities.com/
jvravichandran
- http://www.411asp.net/func/search?
qry=Ravichandran+J.V.&cob=aspnetpro
- http://www.southasianoutlook.com
- http://www.MSDNAA.Net
- http://www.csharphelp.com
- http://www.poetry.com/Publications/
display.asp?ID=P3966388&BN=999&PN=2
- Or, just search on "J.V.Ravichandran"
at http://www.Google.com
 
Thanks Jay. I did realize that but what I was trying to say was that the
more things we place into memory (any memory) will mean more things have to
come out of memory later. And that the sheer act of doing that (whether it
be the GC cleaning the heap or the stack frame being discarded) uses
processor clock cycles.

Thanks again.
 
See my reply to your reply to me above. But isn't it also possible that an
Integer can, in fact, be stored on the heap if it is part of a larger
reference type object?
 
Scott,
As Michael suggests, discarding the stack frame is little (very little) more
then a subtract statement. The number of processor clock cycles is going to
be so insignificant that for the far majority of developers it doesn't
exist.

Just Remember the 80/20 rule. That is 80% of the execution time of your
program is spent in 20% of your code. I will optimize (worry about
performance, memory consumption) the 20% once that 20% has been identified &
proven to be a performance problem via profiling (CLR Profiler is one
profiling tool).

For info on the 80/20 rule & optimizing only the 20% see Martin Fowler's
article "Yet Another Optimization Article" at
http://martinfowler.com/ieeeSoftware/yetOptimization.pdf

Info on the CLR Profiler:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag/html/scalenethowto13.asp

http://msdn.microsoft.com/library/d...y/en-us/dndotnet/html/highperfmanagedapps.asp

Hope this helps
Jay
 
I don't disagree Jay. But the OP was about performance and my answer(s)
were strictly based on that in the most literal of ways.
 
And, that was why when the OP mentioned "integer", I indicated that the heap
can still be a factor.
 
Scott,
See other thread.

Jay

Scott M. said:
And, that was why when the OP mentioned "integer", I indicated that the
heap can still be a factor.
 
Scott,
What I am suggesting is that using a Static may actually hurt performance
not help performance, largely based on the amount of extra IL generated. The
fact the Static Integer is part of containing object or on the heap seems
immaterial to me. As in either case the counter itself is not subject to GC.

Without actually profiling the two methods, neither of use can really claim
which one performs better. Plus I'm sure either of us could contrive
benchmarks that would suggest that one performed better then the other. To
accurately profile the methods you would need to run the code in the
situation that the original OP has.

I find it odd that you appear to be arguing with me, when you initially
stated that performance doesn't matter, I hope you will understand that I am
dropping out of this discussion...

Hope this helps
Jay
 
Herfried,

I found the answers from Scott until he became involved in an academical
discussion very good. Are you asking this as an accademical question for
yourself or to help the OP. I think that makes a big differenc.

I do not like static values, however there where it is for reading better
than a globaly placed value I will use them.

To the OP my answer is why botter about this, keep eye on the structure of
your code. When you need a static variable only in one method, use a static
in the otherway set it global (what does not mean for me directly in the top
of the program).

The performance done with this is about thousands of nanoseconds.

Just my thought,

Cor

"Herfried K. Wagner [MVP]"
 
I am very confused Jay. I haven't argued or disputed anything you've said.
I didn't say you were wrong and I didn't say that Dim or Static was the
better choice. I was simply trying to point out pro's con's of each
scenario. I asked you a question or two to clarify items for me and you
did.

I think you may want to go back and read the thread again. Sorry if you got
the wrong impression.

Thank you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top