Re: syntax question

Tuesday, September 4, 2012

I've put up a test case on jsPerf: http://jsperf.com/comparison-performance

Depending on the engine you might see varying results. You will also notice that your examples aren't the most efficient ones.

The fastest on Safari 6 is the member lookup.
The str in obj is slightly slower.
Regular expressions were the slowest in my case. You can get rid of the positive lookahead if you want exact match anyway to speed it up slightly.

I don't have the setup right here to test more browsers at the moment.

Cheers


On Sun, Aug 26, 2012 at 8:29 PM, thor <jyng7@hotmail.com> wrote:
Thank you, illandril!  :-)


On Saturday, August 25, 2012 12:12:12 PM UTC-5, illandril wrote:
With my tests...
Chrome 22: regular expressions
IE9: str in obj
FF11: str in obj


On Friday, August 24, 2012 10:53:05 PM UTC-4, thor wrote:
Which do you think is more efficient when checking if a string is either "<i>" or "<b>"?

  var obj = {'<b>': null, '<i>': null};
  var str = '<i>';

  var tag = str.search(/<(?:b|i)>/);

or

  var tag = (str in obj);

Thanks!

--
You received this message because you are subscribed to the Google Groups "JavaScript Forum" group.
To view this discussion on the web visit https://groups.google.com/d/msg/javascript-information/-/geGf5LFbYdgJ.

To post to this group, send email to javascript-information@googlegroups.com.
To unsubscribe from this group, send email to javascript-information+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/javascript-information?hl=en.

--
 
 

0 comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Copyright © 2010 Web Design | Free Blogger Templates by Splashy Templates | Layout by Atomic Website Templates

Vida de bombeiro Recipes Informatica Humor Jokes Mensagens Curiosity Saude Video Games Animals Diario das Mensagens Eletronica Rei Jesus News Noticias da TV Artesanato Esportes Noticias Atuais Games Pets Career Religion Recreation Business Education Autos Academics Style Television Programming Motosport Humor News The Games Home Downs World News Internet Design Entertaimment Celebrities 1001 Games Doctor Pets Net Downs World Enter Jesus Mensagensr Android Rub Letras Dialogue cosmetics Genexus lasofia thebushrajr wingshock tripedes gorduravegetal dainfamia dejavu-transpersonal jsbenfica republicadasbadanas ruiherbon iranianforaryans eaystcheyl fotosdanadir Só Humor Curiosity Gifs Medical Female American Health Madeira Designer PPS Divertidas Estate Travel Estate Writing Computer Matilde Ocultos Matilde futebolcomnoticias girassol lettheworldturn topdigitalnet Bem amado enjohnny produceideas foodasticos cronicasdoimaginario downloadsdegraca compactandoletras newcuriosidades blogdoarmario arrozinhoii