• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Find special characters in string (Performance)

 
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Guys,
I need to create a method that determines if certain characters like


Which of this two ways is better in performance? Or is there any better way?


Thanks
Martin
[ April 03, 2006: Message edited by: Martin Lira ]
 
Ranch Hand
Posts: 262
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If no special characters are present, the first method will scan the whole string four times, while the second will only scan it once. Performance-wise, that's the only difference worth noticing, so you might as well go with the second method. But you're probably wasting your effort. Remember the three rules of optimization:

1. Don't do it.
2. Don't do it.
3. Before you do it, complete the app and profile it; the bottlenecks probably aren't where you expect them to be.
 
I love a woman who dresses in stainless steel ... and carries tiny ads:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic