Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

String comparisons vs switch case

 
Sandeep Deshmukh
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Guys,

I have worked on a module in my project within which i have passed module id's to diffrentiate between different calls from within the module . The ids are of String type.
The same module is to be reused as it is almost same as above . I have used module ids again to toggle between the 2 modules. But the procesing has become slow . Is it because of the number of String comparisons. my friend suggested to use switch-case by assigning module id unique integers in begining of method calls and use the switch case for them in subsequent comparisons. Will this be faster than string comaparison?

Sandeep Deshmukh
 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Obviously integer arithimetic operations are faster than string operations.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24213
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Programmers, even very experienced ones, are notoriously bad at guessing at performance bottlenecks. The only really effective way to answer this question is to profile your existing application and see where the bottlenecks are. If it turns out that those String comparisons are slowing things down, then yes, a switch() would likely speed your program up. But until you profile the program, you really don't know what it making it slow. Don't bother guessing, as you're likely to be wrong.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to Performance forum...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!