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:

  1. 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.

  2. 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

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -