0

I found 3 different way to get the value of the src attribute of an img tag in an HTML string.

  1. With a Regex using RegexKitLite.
  2. With TFHpple HTML parser
  3. Using a NSSCanner to scan the HTML string.

So which way I must use to optimize performance of my iPhone app?

Alan Moore
  • 73,866
  • 12
  • 100
  • 156
paul_1991
  • 245
  • 4
  • 13
  • 1
    If you do not know you should measure it. – FrVaBe Aug 03 '11 at 13:54
  • 1
    Parsing HTML with regexes [may not be a good idea](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454). – jscs Aug 03 '11 at 13:58
  • @Claszen how can I miseure it?? Wich app can I use? thanks – paul_1991 Aug 03 '11 at 14:03
  • Independent from what you do I would say to measure the time you **(1)** Take current time on start **(2)** do what you want to measure **(3)** take current time when done **(4)** calculate the time gap. – FrVaBe Aug 03 '11 at 14:12
  • @Josh: true (upvote). Finding an image tag maybe doesn't really count as parsing, but more as trying to find something within a text. At which RegExes do a very good job. – vstrien Aug 05 '11 at 10:48

1 Answers1

1

Maybe not the fastest, but RegEx is imho the most versatile and portable method. And unless you're really doing hundreds of parses per second, you won't notice the performance hit you'll get by not using the fastest method around..

I use lots of regexes on iPhone for user input validation while the user is entering text (so a lag would certainly be seen). Never had any problems.

vstrien
  • 2,547
  • 3
  • 27
  • 47