Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Regular Expressions Performance

Regular Expressions Performance

Scheduled Pinned Locked Moved C#
performancequestion
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    yftah1989
    wrote on last edited by
    #1

    I'm creating a new program. The ONLY thing which is important for me is the running time of the program. Should I use a regular expressions, or maybe should I write my own search code?

    P L R 3 Replies Last reply
    0
    • Y yftah1989

      I'm creating a new program. The ONLY thing which is important for me is the running time of the program. Should I use a regular expressions, or maybe should I write my own search code?

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      Without knowing what you are trying to achieve, it's hard to give any answers. I will say that a well designed regular expression will generally be faster than a roll your own search and replace algorithm, but a badly designed one can really kill performance when applied to large a data set. If, however, your search/replace doesn't naturally fit into a regular expression don't worry about it. Far too many times, people will contort themselves to write hugely complex regular expressions when a simple string.Replace would have sufficed.

      "WPF has many lovers. It's a veritable porn star!" - Josh Smith

      As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

      My blog | My articles | MoXAML PowerToys | Onyx

      1 Reply Last reply
      0
      • Y yftah1989

        I'm creating a new program. The ONLY thing which is important for me is the running time of the program. Should I use a regular expressions, or maybe should I write my own search code?

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        A regex may win when it involves a complex operation that fits well with a regex approach; OTOH most of the time regexes are both more cryptic and slower than a few explicit string operations. I once performed this experiment[^]. :)

        Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

        Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

        1 Reply Last reply
        0
        • Y yftah1989

          I'm creating a new program. The ONLY thing which is important for me is the running time of the program. Should I use a regular expressions, or maybe should I write my own search code?

          R Offline
          R Offline
          riced
          wrote on last edited by
          #4

          I'd say write your program whichever way suits you. Then if performance is a problem profile it to find out where it is spending time. Then, and only then, think about how to speed it up. As has been pointed out, regexes may be faster, then again they may be slower.

          Regards David R --------------------------------------------------------------- "Every program eventually becomes rococo, and then rubble." - Alan Perlis The only valid measurement of code quality: WTFs/minute.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups