Temos também o Inline::CPP (<a href="http://search.cpan.org/~shassan/Inline-CPP/lib/Inline/CPP.pod">http://search.cpan.org/~shassan/Inline-CPP/lib/Inline/CPP.pod</a>)!<br clear="all"><br>ABS()<br><br>
<br><br><div class="gmail_quote">2010/11/6 Renato Santos <span dir="ltr"><<a href="mailto:renato.cron@gmail.com">renato.cron@gmail.com</a>></span><br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<p>ThannkS! Devo aprender a fazer extensões em XS</p>
<p>O q acho meio chato, e q precisa ser em c puro, sem c++.<br>
Ou, criar uma lib em c++ e um link com C e um Xx pra perl.</p>
<p></p><blockquote type="cite">Em nov 6, 2010 11:05 PM, "Stanislaw Pusep" <<a href="mailto:creaktive@gmail.com" target="_blank">creaktive@gmail.com</a>>escreveu:<div class="im"><br><br>List::Util wins, flawless victory!<br>
(resultado para um array de 100 elementos)<br>
<br><span style="font-family: courier new,monospace;"> Rate alg_num_shuffle pusep map sort fisher_yates list_util</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">alg_num_shuffle 10104/s -- -1% -2% -18% -19% -91%</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">pusep 10172/s 1% -- -2% -18% -18% -90%</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">map 10342/s 2% 2% -- -16% -17% -90%</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">sort 12332/s 22% 21% 19% -- -1% -88%</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">fisher_yates 12458/s 23% 22% 20% 1% -- -88%</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">list_util 106762/s 957% 950% 932% 766% 757% --</span><br>
<br>Aliás, aquele código que postei inicialmente era uma variante do algoritmo de Fisher-Yates (<a href="http://en.wikipedia.org/wiki/Fisher-Yates" target="_blank">http://en.wikipedia.org/wiki/Fisher-Yates</a>) que fiz em 2 minutos. Refiz decentemente e teve uma melhoria significativa. O que salva a minha reputação é que o Algorithm::Numerical::Shuffle traz uma outra implementação do mesmíssimo algoritmo e ainda assim é capenga... Muita coragem para publicar no CPAN, hein :)<br>
"map" e "sort" são gambiarras one-liners. O engraçado é que shuffle via sort é bem mais eficiente do que os outros (menos o List::Util que é XS) para arrays pequenos (10 elementos):<br><br><span style="font-family: courier new,monospace;"> Rate pusep alg_num_shuffle map fisher_yates sort list_util<br>
pusep 92304/s -- -1% -7% -16% -54% -89%</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">alg_num_shuffle 92781/s 1% -- -6% -15% -54% -89%</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">map 99073/s 7% 7% -- -10% -51% -88%</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">fisher_yates 109484/s 19% 18% 11% -- -46% -87%</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">sort 202283/s 119% 118% 104% 85% -- -76%</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">list_util 838226/s 808% 803% 746% 666% 314% --</span><br style="font-family: courier new,monospace;">
<br>E aqui está o código do benchmark: <a href="http://tinypaste.com/f989dd" target="_blank">http://tinypaste.com/f989dd</a><br><br>ABS()</div><p><font color="#500050">
2010/11/6 Renato Santos <<a href="mailto:renato.cron@gmail.com" target="_blank">renato.cron@gmail.com</a>>
>
> Preciso ao menos comparar com a solução do P...</font></p><div class="im"><br>_______________________________________________<br>
SaoPaulo-pm mailing list<br>
<a href="mailto:SaoPaulo-pm@pm.org" target="_blank">SaoPaulo-pm@pm.org</a><br>
<a href="http://mail.pm.org/mailman/listinfo/saopaulo-pm" target="_blank">http://mail.pm.org/mailman/listinfo/saopaulo-pm</a><br></div></blockquote>
<br>_______________________________________________<br>
SaoPaulo-pm mailing list<br>
<a href="mailto:SaoPaulo-pm@pm.org">SaoPaulo-pm@pm.org</a><br>
<a href="http://mail.pm.org/mailman/listinfo/saopaulo-pm" target="_blank">http://mail.pm.org/mailman/listinfo/saopaulo-pm</a><br></blockquote></div><br>