<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Rogério Lino &#187; Benchmark</title>
	<atom:link href="http://rogeriolino.com/categorias/benchmark/feed/" rel="self" type="application/rss+xml" />
	<link>http://rogeriolino.com</link>
	<description>Desenvolvimento Web, tecnologia, jogos e etcetera</description>
	<lastBuildDate>Wed, 16 May 2012 19:51:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Javascript Benchmark: replaceAll</title>
		<link>http://rogeriolino.com/2009/01/07/javascript-benchmark-replaceall/</link>
		<comments>http://rogeriolino.com/2009/01/07/javascript-benchmark-replaceall/#comments</comments>
		<pubDate>Wed, 07 Jan 2009 17:06:39 +0000</pubDate>
		<dc:creator>Rogério Alencar Lino Filho</dc:creator>
				<category><![CDATA[Benchmark]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[join]]></category>
		<category><![CDATA[regexp]]></category>
		<category><![CDATA[replace]]></category>
		<category><![CDATA[replaceAll]]></category>
		<category><![CDATA[split]]></category>

		<guid isPermaLink="false">http://rogeriolino.wordpress.com/?p=127</guid>
		<description><![CDATA[<p>Há algum tempo <a title="replaceAll()" href="http://rogeriolino.wordpress.com/2007/07/23/javascript-replaceall/">escrevi um post contendo</a> um exemplo de método para fazer replace em toda String. No caso o método que escrevi usava while e realmente é muito menos eficiente do que as alternativas apresentadas nos comentários, a primeira usando Expressão Regular (sugerida pelo <a title="Blog do Almir" href="http://www.almirmendes.net/">Almir Mendes</a>) e a [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>Há algum tempo <a title="replaceAll()" href="http://rogeriolino.wordpress.com/2007/07/23/javascript-replaceall/">escrevi um post contendo</a> um exemplo de método para fazer replace em toda String. No caso o método que escrevi usava <strong>while</strong> e realmente é muito menos eficiente do que as alternativas apresentadas nos comentários, a primeira usando <strong>Expressão Regular</strong> (sugerida pelo <a title="Blog do Almir" href="http://www.almirmendes.net/">Almir Mendes</a>) e a segunda utilizando <strong>split</strong> e <strong>join</strong> (sugerida pelo <a title="Blog do Lucas Ferreira" href="http://blog.lucasferreira.com/">Lucas Ferreira</a>).  Então resolvi (depois de muito tempo) fazer um benchmark utilizando os três métodos para poder chegar a uma conclusão sobre qual seria melhor.</p>
<p>Fiquei muito surpreso com os testes, não porque o método utilizando while foi de longe o pior entre os três, mas sim pelo fato do método que consiste em dividir a String em um vetor e depois junta-la novamente (<strong>split+join</strong>) ter sido mais rápido do que o próprio método de replace do javascript utilizando Expressão Regular (já que o split também utiliza ER).</p>
<p>Outro fato interessante é que tanto utilizando <strong>ER</strong> quanto <strong>split-join</strong> os métodos se mostraram bastante escaláveis, enquanto o com <strong>while</strong> piora consideravelmente conforme o número de ocorrência aumenta.</p>
<p>Lembrando que fiz os testes através <a title="replaceAll" href="http://www17.brinkster.com/chivalrous/exemplos/benchmark/javascript/replace_all.html">desta página</a> que criei utilizando como browser o <a title="Get Firefox" href="http://pt-br.www.mozilla.com/pt-BR/firefox/">Firefox 3.0.5</a>. Caso alguém faça os testes e obtenha resultados diferente gostaria de receber feedbacks.</p>
<div class="shr-publisher-127"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http%3A%2F%2Frogeriolino.com%2F2009%2F01%2F07%2Fjavascript-benchmark-replaceall%2F' data-shr_title='Javascript+Benchmark%3A+replaceAll'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Frogeriolino.com%2F2009%2F01%2F07%2Fjavascript-benchmark-replaceall%2F' data-shr_title='Javascript+Benchmark%3A+replaceAll'></a><a class='shareaholic-tweetbutton' data-shr_count='horizontal' data-shr_href='http%3A%2F%2Frogeriolino.com%2F2009%2F01%2F07%2Fjavascript-benchmark-replaceall%2F' data-shr_title='Javascript+Benchmark%3A+replaceAll'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://rogeriolino.com/2009/01/07/javascript-benchmark-replaceall/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

