Performance issue

Accessing a variable in stack(with in a method)

Accessing an object in heap

which is more efficient?

consider

public void getValues(request)

{

Map parameterMap=request.getParameterMap();

String first=parameterMap.get("fist");

}

request-object reference not local to this method

but parameterMap is local to this method

so which is more efficient ?

(request.getParameterMap()or parameterMap.get())

[475 byte] By [yoga_harisha] at [2007-10-3 10:43:46]
# 1

These kind of questions are usually pointless. The difference (if there is any) is far to small to make any difference in almost all cases.

And if you really want to know the answer, why don't you simply test it? Write a small program that does it (both ways) and let each way run a couple of million times and look how long it takes.

JoachimSauera at 2007-7-15 6:07:51 > top of Java-index,Java Essentials,Java Programming...
# 2
Whether or not a variable is local is a design decision not a performance one.
YoGeea at 2007-7-15 6:07:51 > top of Java-index,Java Essentials,Java Programming...
# 3
in extreme cases it might matter (stack versus heap, things like that), but if you need to worry over a few microseconds difference in call times you will have been given the training to know such things already (and will almost certainly be programming in Assembler or at worst C, not
jwentinga at 2007-7-15 6:07:51 > top of Java-index,Java Essentials,Java Programming...