Instance of performance in Java -
i working on tcp server application. when message received, new instance of object representing message created. À function in messages handler called , new instance passed parameter. parameter of type "imessage" (interface message). @ point, need identify message type.
my question : in order have best performences, should add à unique identifier in each imessage instance, int, or should use instanceof ?
you asking if faster test integer field or use instanceof
.
there 2 answers:
it depends on actual code write, , platform run on. way know sure write code (both versions) , either benchmark them, or dump native codes jit compiler emits , analyse , compare them1.
the answer doesn't matter. percentage of time spent in
if
test in dispatching message tiny compared rest of application. (and if performance really matters you, should implementing server in c or c++.)
1 - later requires deep understanding how assembly code performs. difficult topic.
Comments
Post a Comment