1 2 3 Previous Next 216 Replies Latest reply: Sep 29, 2008 4:18 AM by 796440 RSS

    static vs singleton performance

    807589
      I'm searching for the best performance.
      Static or singleton?

      And please, i dont need to know singleton are more flexible and maintainable, i'm only looking for the performance fact.

      :) Thanks all.
        • 1. Re: static vs singleton performance
          807589
          There is no performance difference that you'd ever notice
          • 2. Re: static vs singleton performance
            jwenting
            but do remember that singletons aren't.
            • 3. Re: static vs singleton performance
              807589
              Seriously?
              I mean, isn't there more memory allocation for a singleton than for a static for example?
              • 4. Re: static vs singleton performance
                807589
                jwenting wrote:
                but do remember that singletons aren't.
                Please, explain me that :) im curious to know how static would be more flex than singleton
                • 5. Re: static vs singleton performance
                  JoachimSauer
                  p0LyeSt3R wrote:
                  Seriously?
                  I mean, isn't there more memory allocation for a singleton than for a static for example?
                  The One-time allocation of the singelton will be so small that you will never, ever notice the performance inpact. There are usually hundreds or thousands of other decisions in your application that will have a much bigger impact on it's performance than this one.
                  • 6. Re: static vs singleton performance
                    807589
                    JoachimSauer wrote:
                    The One-time allocation of the singelton will be so small that you will never, ever notice the performance inpact. There are usually hundreds or thousands of other decisions in your application that will have a much bigger impact on it's performance than this one.
                    I know that surely my app doesn't need that performance, but i was just wondering which method would be less expensive, u know, just to have the feeling my code is the best possible i can get :)
                    • 7. Re: static vs singleton performance
                      JoachimSauer
                      p0LyeSt3R wrote:
                      I know that surely my app doesn't need that performance, but i was just wondering which method would be less expensive, u know,
                      ok
                      just to have the feeling my code is the best possible i can get :)
                      Then you are measuring the wrong thing. Readability, simplicity and maintainability are much more important than that dubious performance. Especially when you know that performance won't be a problem in that part.

                      Write the code that is easiest to read, understand and change.
                      • 8. Re: static vs singleton performance
                        796440
                        p0LyeSt3R wrote:
                        And please, i dont need to know singleton are more flexible and maintainable, i'm only looking for the performance fact.
                        Then you're putting the cart before the horse.
                        • 9. Re: static vs singleton performance
                          807589
                          JoachimSauer wrote:
                          Then you are measuring the wrong thing. Readability, simplicity and maintainability are much more important than that dubious performance. Especially when you know that performance won't be a problem in that part.

                          Write the code that is easiest to read, understand and change.
                          Thanks for that, but im not newb =P

                          I was searching more for a java-technique answer like :
                          "Static methods are not instance-methods(im sure that's stupid lol) so they reside at X queue in memory whereas instance-methods get another portion of memory, blablabla performance blablabla ...".

                          But thanks anyways =D
                          • 10. Re: static vs singleton performance
                            796440
                            p0LyeSt3R wrote:
                            JoachimSauer wrote:
                            The One-time allocation of the singelton will be so small that you will never, ever notice the performance inpact. There are usually hundreds or thousands of other decisions in your application that will have a much bigger impact on it's performance than this one.
                            I know that surely my app doesn't need that performance, but i was just wondering which method would be less expensive, u know, just to have the feeling my code is the best possible i can get :)
                            There will probably never be a case where choosing on this issue for performance reasons will make your code better.
                            • 11. Re: static vs singleton performance
                              796440
                              p0LyeSt3R wrote:
                              JoachimSauer wrote:
                              Then you are measuring the wrong thing. Readability, simplicity and maintainability are much more important than that dubious performance. Especially when you know that performance won't be a problem in that part.

                              Write the code that is easiest to read, understand and change.
                              Thanks for that, but im not newb =P
                              You're taking a very noob stance on this.
                              I was searching more for a java-technique answer like :
                              "Static methods are not instance-methods(im sure that's stupid lol) so they reside at X queue in memory whereas instance-methods get another portion of memory, blablabla performance blablabla ...".
                              If you're able to understand that kind of answer, you're able to research it yourself in the JLS and JVM Spec, and run tests of your own
                              • 12. Re: static vs singleton performance
                                JoachimSauer
                                p0LyeSt3R wrote:
                                JoachimSauer wrote:
                                Then you are measuring the wrong thing. Readability, simplicity and maintainability are much more important than that dubious performance. Especially when you know that performance won't be a problem in that part.

                                Write the code that is easiest to read, understand and change.
                                Thanks for that, but im not newb =P
                                And what exactly does that mean? That you still believe performance is a more important metric than maintainability in general?
                                I was searching more for a java-technique answer like :
                                "Static methods are not instance-methods(im sure that's stupid lol) so they reside at X queue in memory whereas instance-methods get another portion of memory, blablabla performance blablabla ...".
                                For the java-technique answer look through the JLS and the JVM spec an do your own benchmarks (taking care of the common micro-benchmark pitfalls, 'though).

                                For all intent and purpose the answer "The performance difference, if any, will be negligible in all but the most obscure cases" is the valid one to your question.

                                Edit: which is exactly what jverd said just now ...
                                • 13. Re: static vs singleton performance
                                  807589
                                  That's why the answer should have been from the beginning "*I don't know*, you should read JVM specs", instead of thinking i dont know what im talking about and answering me things that had nothing to do with my question but increase your "guru-OO-maintainability-ego", wasting both my and your time.

                                  Thanks anyways.
                                  • 14. Re: static vs singleton performance
                                    807589
                                    JoachimSauer wrote:
                                    For all intent and purpose the answer "The performance difference, if any, will be negligible in all but the most obscure cases" is the valid one to your question.
                                    No way!!....
                                    1 2 3 Previous Next