<?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>Meu Post &#187; C++</title>
	<atom:link href="http://www.meupost.com/tag/c/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.meupost.com</link>
	<description>Programação, diversão e arte. Por Ricardo Giaviti</description>
	<lastBuildDate>Mon, 30 Aug 2010 11:27:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Configurando ambiente de desenvolvimento C++ no Windows com Eclipse e MinGW</title>
		<link>http://www.meupost.com/2009/05/11/configurando-ambiente-de-desenvolvimento-c-no-windows-com-eclipse-e-mingw/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=configurando-ambiente-de-desenvolvimento-c-no-windows-com-eclipse-e-mingw</link>
		<comments>http://www.meupost.com/2009/05/11/configurando-ambiente-de-desenvolvimento-c-no-windows-com-eclipse-e-mingw/#comments</comments>
		<pubDate>Mon, 11 May 2009 13:15:22 +0000</pubDate>
		<dc:creator>RicardoSEP</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[IDE]]></category>
		<category><![CDATA[mingw]]></category>
		<category><![CDATA[Programação]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.meupost.com/?p=338</guid>
		<description><![CDATA[O Eclipse é uma das melhores IDEs de desenvolvimento Java no mercado. O que pouca gente sabe, é que ela também pode ser usada para desenvolvimento de aplicações utilizando o C++. Nesse pequeno tutorial, mostrarei como instalar o compilador C++ para Windows (MinGW) e utilizar o Eclipse para trabalhar com esse compilador. O compilador MinGW


Related posts:<ol><li><a href='http://www.meupost.com/2008/07/07/fazendo-o-eclipse-rodar-sobre-uma-vm-especifica/' rel='bookmark' title='Permanent Link: Fazendo o Eclipse rodar sobre uma VM específica'>Fazendo o Eclipse rodar sobre uma VM específica</a></li>
<li><a href='http://www.meupost.com/2010/07/26/montando-ambiente-completo-windows-apache-php-mysql-com-xampp/' rel='bookmark' title='Permanent Link: Montando ambiente completo Windows + Apache + PHP + MySQL com XAMPP'>Montando ambiente completo Windows + Apache + PHP + MySQL com XAMPP</a></li>
<li><a href='http://www.meupost.com/2010/07/03/usando-breakpoint-condicional-no-eclipse/' rel='bookmark' title='Permanent Link: Usando breakpoint condicional no Eclipse'>Usando breakpoint condicional no Eclipse</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div id="HOTWordsTxt" name="HOTWordsTxt"><p style="text-align: left;">O Eclipse é uma das melhores IDEs de desenvolvimento Java no mercado. O que pouca gente sabe, é que ela também pode ser usada para desenvolvimento de aplicações utilizando o C++. Nesse pequeno tutorial, mostrarei como <strong>instalar o compilador C++ para Windows (MinGW) e utilizar o Eclipse para trabalhar com esse compilador.</strong></p>
<p>O compilador MinGW (Minimalist GNU for Windows) é uma versão portada para Microsoft Windows do conjunto de ferramentas GNU. Este software inclui um conjunto de arquivos cabeçalho para a API do Windows que permite aos desenvolvedores usar o GCC para criar programas nativos em Windows sem precisar contar com uma emulação em tempo real de um sistema Unix-like.<br />
<strong><br />
Ambiente usado nesse tutorial:</strong></p>
<ul>
<li>Windows XP SP2</li>
<li>Eclipse 3.4 &#8211; Ganymede C++</li>
</ul>
<p style="text-align: left;">O primeiro passo é baixar o Eclipse para C++. Para isso, vá ao site oficial do Eclipse (<a href="http://www.eclipse.org"><strong>http://www.eclipse.org</strong></a>), clique em &#8220;<strong>Download Eclipse</strong>&#8221; e baixe a última versão do &#8220;<strong>Eclipse IDE for C/C++ Developers</strong>&#8220;. O Eclipse vem em uma pacote ZIP (quando Windows) com aproximadamento 68MB. Feito o download do Eclipse, descompacte o arquivo ZIP. Agora vamos ao próximo passo.</p>
<p>Nesse segundo passo, vamos baixar o MinGW, que é o compilador que utilizaremos. Acessem o site do MinGW <strong>(<a href="http://www.mingw.org">http://www.mingw.org</a>)</strong>, vá em &#8220;<strong>Downloads</strong>&#8221; e baixe a última versão do &#8220;<strong>Automated MinGW Installer</strong>&#8220;. Enquanto esse artigo esta sendo escrito, a última versão é a MinGW 5.1.4 de 26/04/2008. O arquivo é pequeno porque toda a instalação será feita online. Ele baixará todos os arquivos necessários na hora da instalação.</p>
<p>Existe alguns detalhes para se instalar o MinGW. Duplo clique no instalador e vamos começar a instalação. <strong>Você deverá estar conectado a Internet para instalar o MinGW com sucesso</strong>. Na primeira tela, clique em &#8220;<strong>Next</strong>&#8220;. Na segunda, marque a opção &#8220;<strong>Download and install</strong>&#8220;, igual na figura abaixo.</p>
<p><a href="http://www.meupost.com/wp-content/uploads/2009/05/mingw1.jpg"><img class="size-medium wp-image-339 alignnone" title="mingw1" src="http://www.meupost.com/wp-content/uploads/2009/05/mingw1-300x234.jpg" alt="mingw1" width="300" height="234" /></a></p>
<p>Depois clique em &#8220;<strong>I Agree</strong>&#8221; para aceitar a licensa GPL e na tela de escolha de pacote (Choose Package), marque a opção &#8220;<strong>Current</strong>&#8220;, para instalar a versão estável atual do MinGW.</p>
<ul style="text-align: left;">
<li><strong>Previous</strong>: Versão estável anterior;</li>
<li><strong>Current</strong>: Versão atual estável;</li>
<li><strong>Candidate</strong>: Versão futura porém instável;</li>
</ul>
<p style="text-align: left;"><a href="http://www.meupost.com/wp-content/uploads/2009/05/mingw2.jpg"><img class="alignnone size-medium wp-image-340" title="mingw2" src="http://www.meupost.com/wp-content/uploads/2009/05/mingw2-300x234.jpg" alt="mingw2" width="300" height="234" /></a></p>
<p>Na escolha de componentes (Choose Components), você deverá obrigatoriamente marcar as opções:</p>
<ul style="text-align: left;">
<li>MinGW base tools;</li>
<li>g++ compiler</li>
</ul>
<p style="text-align: left;">As outras opções (g77 compiler, Ada compiler&#8230;) são opcionais. Elas não são necessárias para o que pretendemos fazer com esse tutotial. Instale se você quiser.</p>
<p><a href="http://www.meupost.com/wp-content/uploads/2009/05/mingw3.jpg"><img class="alignnone size-medium wp-image-341" title="mingw3" src="http://www.meupost.com/wp-content/uploads/2009/05/mingw3-300x234.jpg" alt="mingw3" width="300" height="234" /></a></p>
<p>Clique em &#8220;<strong>Next</strong>&#8221; e escolha o diretório de instalação. O diretório padrão e recomendado é o &#8220;<strong>C:\MinGW</strong>&#8220;. Avance mais uma vez e o instalador irá começar a fazer o download dos componentes e a instalação dos mesmos.</p>
<p><a href="http://www.meupost.com/wp-content/uploads/2009/05/mingw4.jpg"><img class="alignnone size-medium wp-image-342" title="mingw4" src="http://www.meupost.com/wp-content/uploads/2009/05/mingw4-300x101.jpg" alt="mingw4" width="300" height="101" /></a></p>
<p>Após terminar, finalize o instalador e abra o Eclipse (que você descompactou no primeiro passo). Para rodar o Eclipse você irá precisar da JRE instalada. Caso você não tenha a JRE, basta fazer o download aqui: <a href="http://java.sun.com/javase/downloads/index.jsp"><strong>http://java.sun.com/javase/downloads/index.jsp</strong></a>. Selecione a opção: &#8220;<strong>Java SE Runtime Environment (JRE)</strong>&#8220;.</p>
<p>Com o Eclipse aberto, teremos a seguinte tela:</p>
<p><a href="http://www.meupost.com/wp-content/uploads/2009/05/eclipse1.jpg"><img class="alignnone size-medium wp-image-343" title="eclipse1" src="http://www.meupost.com/wp-content/uploads/2009/05/eclipse1-300x225.jpg" alt="eclipse1" width="300" height="225" /></a></p>
<p>Até aí tudo certo? Agora vamos criar o nosso projetinho C++ de exemplo para ver se está tudo OK e se a compilação está funcionando. Para criar o projeto faça: &#8220;<strong>File &gt; New &gt; C++ Project</strong>&#8220;. Digite um nome para seu projeto e escolha a opção &#8220;<strong>Hello World C++ Project</strong>&#8220;. Verifique se o MinGW aparece no <strong>Toolchains</strong>. Abaixo segue uma figura para você ter uma referência:</p>
<p><a href="http://www.meupost.com/wp-content/uploads/2009/05/eclipse2.jpg"><img class="alignnone size-medium wp-image-344" title="eclipse2" src="http://www.meupost.com/wp-content/uploads/2009/05/eclipse2-271x300.jpg" alt="eclipse2" width="271" height="300" /></a></p>
<p>Agora clique em &#8220;<strong>Finish</strong>&#8221; e vamos testar. O projeto será criado e você pode fechar essa tela de &#8220;<strong>Welcome</strong>&#8221; que aparece quando se inicia o Eclipse. Repare que o projeto criado está no lado esquerdo do Eclipse. Essa janela onde fica os projetos é chamada de &#8220;<strong>Project Explorer</strong>&#8220;. Expanda seu projeto, vá na pasta src e duplo clique no arquivo &#8220;<strong>Teste.cpp</strong>&#8220;. Você terá um código igual ao abaixo:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #666666;">//============================================================================</span>
<span style="color: #666666;">// Name        : Teste.cpp</span>
<span style="color: #666666;">// Author      : </span>
<span style="color: #666666;">// Version     :</span>
<span style="color: #666666;">// Copyright   : Your copyright notice</span>
<span style="color: #666666;">// Description : Hello World in C++, Ansi-style</span>
<span style="color: #666666;">//============================================================================</span>
&nbsp;
<span style="color: #339900;">#include &lt;iostream&gt;</span>
<span style="color: #0000ff;">using</span> <span style="color: #0000ff;">namespace</span> std<span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">int</span> main<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;!!!Hello World!!!&quot;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span> <span style="color: #666666;">// prints !!!Hello World!!!</span>
	<span style="color: #0000ff;">return</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>Abaixo segue uma screenshot do Eclipse para você ter uma referência de como estarão as coisas nesse momento.</p>
<p><a href="http://www.meupost.com/wp-content/uploads/2009/05/eclipse3.jpg"><img class="alignnone size-medium wp-image-345" title="eclipse3" src="http://www.meupost.com/wp-content/uploads/2009/05/eclipse3-300x225.jpg" alt="eclipse3" width="300" height="225" /></a></p>
<p>Agora vamos rodar o projeto. Para compilar e rodar esse projeto, clique no &#8220;<strong>Play</strong>&#8221; na barra de ferramentas lá em cima no Eclipse. Se tudo der certo, no console dele irá aparecer &#8220;<strong>!!!Hello World!!!</strong>&#8220;. Se aparecer, quer dizer que deu tudo certo e seu Eclipse está prontinho para ser usado como uma IDE de desenvovlimento C++.</p>
<p><a href="http://www.meupost.com/wp-content/uploads/2009/05/eclipse4.jpg"><img class="alignnone size-medium wp-image-346" title="eclipse4" src="http://www.meupost.com/wp-content/uploads/2009/05/eclipse4-300x225.jpg" alt="eclipse4" width="300" height="225" /></a></p>
<p>Existem muitos livros e muitos tutoriais na Internet sobre C++. De uma pesquisada no Google sobre o assunto e você verá quanta informação você achará. Até a próxima e bons estudos.</p>
<p><strong>Fontes:</strong><br />
Explicação sobre o MinGW: <a href="http://pt.wikipedia.org/wiki/MinGW">http://pt.wikipedia.org/wiki/MinGW</a></p>
</div>

<p>Related posts:<ol><li><a href='http://www.meupost.com/2008/07/07/fazendo-o-eclipse-rodar-sobre-uma-vm-especifica/' rel='bookmark' title='Permanent Link: Fazendo o Eclipse rodar sobre uma VM específica'>Fazendo o Eclipse rodar sobre uma VM específica</a></li>
<li><a href='http://www.meupost.com/2010/07/26/montando-ambiente-completo-windows-apache-php-mysql-com-xampp/' rel='bookmark' title='Permanent Link: Montando ambiente completo Windows + Apache + PHP + MySQL com XAMPP'>Montando ambiente completo Windows + Apache + PHP + MySQL com XAMPP</a></li>
<li><a href='http://www.meupost.com/2010/07/03/usando-breakpoint-condicional-no-eclipse/' rel='bookmark' title='Permanent Link: Usando breakpoint condicional no Eclipse'>Usando breakpoint condicional no Eclipse</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.meupost.com/2009/05/11/configurando-ambiente-de-desenvolvimento-c-no-windows-com-eclipse-e-mingw/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Comparação de desempenho entre linguagens de programação</title>
		<link>http://www.meupost.com/2008/07/27/comparacao-de-desempenho-entre-linguagens-de-programacao/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=comparacao-de-desempenho-entre-linguagens-de-programacao</link>
		<comments>http://www.meupost.com/2008/07/27/comparacao-de-desempenho-entre-linguagens-de-programacao/#comments</comments>
		<pubDate>Sun, 27 Jul 2008 15:22:52 +0000</pubDate>
		<dc:creator>RicardoSEP</dc:creator>
				<category><![CDATA[Programação]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[comparativo]]></category>
		<category><![CDATA[desempenho]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JRuby]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.meupost.com/?p=41</guid>
		<description><![CDATA[No dia 08/07/2008 o blog var/log/mind publicou uma comparação de desempenho entre algumas linguagens de programação. As linguagens testadas pelo blog foram C++, JAVA, Ruby, JRuby, Python, Jython, Groovy e PHP. Esse tema gerou até um bafafá na blogosfera nacional e internacional. A tipo de benchmark feito pelo é blog foi bem simples e baseado


Related posts:<ol><li><a href='http://www.meupost.com/2008/11/18/fatorial-recursivo-em-java-e-ruby/' rel='bookmark' title='Permanent Link: Fatorial recursivo em Java e Ruby'>Fatorial recursivo em Java e Ruby</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div id="HOTWordsTxt" name="HOTWordsTxt"><p>No dia 08/07/2008 o blog <a href="http://blog.dhananjaynene.com/2008/07/performance-comparison-c-java-python-ruby-jython-jruby-groovy/"><strong>var/log/mind</strong></a> publicou uma comparação de desempenho entre algumas linguagens de programação. As linguagens testadas pelo blog foram <strong>C++, JAVA, Ruby, JRuby, Python, Jython, Groovy e PHP</strong>. Esse tema gerou até um bafafá na blogosfera nacional e internacional.</p>
<p>A tipo de benchmark feito pelo é blog foi bem simples e baseado em um pedaço de lógica onde é medido o tempo de cada iteração num total de <span><span class="number">100000</span><span> iterações.</span></span></p>
<p>O mais espantoso foi que JAVA obteve um desempenho melhor do que C++. Esse resultado me deixou com uma pulga atrás da orelha porque sempre acreditei (mas nunca havia testado) de que C++ por ser somente compilado seria bem mais rápido do que JAVA que é compilado e interpretado pela JVM.</p>
<p>Então resolvi fazer o mesmo teste que o blog var/log/mind fez. Utilizei os mesmos códigos disponibilizados por ele e rodei eles em minha máquina. <strong>Somente não testei Python, Jython e o Groovy</strong>.</p>
<h3>Ambiente de Testes</h3>
<p>Meu ambiente de testes difere do ambiente de testes do var/log/mind (veja a tabela mais abaixo), assim como versões de compiladores e interpretadores. Abaixo segue o meu ambiente de testes e mais um pouco abaixo as versões dos compiladores e interpretadores usados no teste.</p>
<p>Meu ambiente:</p>
<ul>
<li>Processador: AMD 4200+ X2 64 Bits</li>
<li>Memória: 3GB RAM</li>
<li>SO: Windows XP SP2 Professional</li>
</ul>
<p>As diferenças entre o ambiente de teste original do var/log/mind e o meu ambiente de teste:</p>
<table border="1" cellspacing="0" cellpadding="2" width="100%">
<tbody>
<tr>
<th width="20%" scope="col"></th>
<th width="40%" scope="col">MeuPost.com</th>
<th width="40%" scope="col">var/log/mind</th>
</tr>
<tr>
<th width="20%" scope="row">Processador</th>
<td width="40%">AMD 4200+ X2 64 Bits</td>
<td width="40%">Intel® Core™ Duo CPU      T2600  @ 2.16GHz</td>
</tr>
<tr>
<th width="20%" scope="row">Memória</th>
<td width="40%">3GB RAM</td>
<td width="40%">2GB</td>
</tr>
<tr>
<th width="20%" scope="row">SO:</th>
<td width="40%">Windows XP SP2 Professional</td>
<td width="40%">Ubuntu Gutsy Gibbon 7.10</td>
</tr>
</tbody>
</table>
<p>Compiladores e Interpretadores usados:</p>
<ul>
<li>C++: MinGW32 GCC: 3.4.2</li>
<li>JAVA 1.6</li>
<li>Ruby 1.8.6-26</li>
<li>JRuby 1.1</li>
<li>PHP 5.2.3</li>
</ul>
<h3>Teste:</h3>
<p>Para realizar o teste rodei 5 vezes o código de cada linguagem diferente e anotei todos os resultados em nanossegundos. Depois tirei a média dos resultados.</p>
<h3>Resultados</h3>
<p>Seguinte a tendência dos resultados, em meu ambiente JAVA também foi superior ao C++. Os resultados também mostraram que o Python está mais maduro que Ruby embora nas últimas versões do Ruby (1.9) o desempenho tenha melhorado muito.</p>
<p>Outro fato interessante é que o JRuby está também mais rápido que Ruby. Já o PHP mostra a força de sua maturidade e popularidade ganhando tanto do Ruby como do JRuby, isso em meu ambiente, porque no var/log/mind tanto o Ruby como o JRuby ganharam do PHP.</p>
<p>Acredito que esse desempenho superior do Ruby no var/log/mind está diretamente associado ao sistema operacional. O Ruby está rodando muito mais rápido em ambientes Linux do que em Windows.</p>
<p>Abaixo segue a tabela de resultados:</p>
<table border="1" cellspacing="0" cellpadding="2" width="100%">
<tbody>
<tr>
<td width="73" height="17" align="left"></td>
<td width="90" align="center"><strong>Iteração 1</strong></td>
<td width="90" align="center"><strong>Iteração 2</strong></td>
<td width="90" align="center"><strong>Iteração 3</strong></td>
<td width="90" align="center"><strong>Iteração 4</strong></td>
<td width="90" align="center"><strong>Iteração 5</strong></td>
<td width="103" align="center"><strong>Média</strong></td>
<td width="88" align="center"><strong>Total</strong></td>
</tr>
<tr>
<td height="17" align="center"><strong>C++</strong></td>
<td align="right">12000</td>
<td align="right">12000</td>
<td align="right">12000</td>
<td align="right">12000</td>
<td align="right">12000</td>
<td align="right">12000</td>
<td align="right">60000</td>
</tr>
<tr>
<td height="17" align="center"><strong>Java</strong></td>
<td align="right" bgcolor="#e6e6e6">1509</td>
<td align="right" bgcolor="#e6e6e6">1369</td>
<td align="right" bgcolor="#e6e6e6">1384</td>
<td align="right" bgcolor="#e6e6e6">1376</td>
<td align="right" bgcolor="#e6e6e6">1385</td>
<td align="right" bgcolor="#e6e6e6">1404,6</td>
<td align="right" bgcolor="#e6e6e6">7023</td>
</tr>
<tr>
<td height="17" align="center"><strong>Ruby</strong></td>
<td align="right">491990</td>
<td align="right">493750</td>
<td align="right">494690</td>
<td align="right">493280</td>
<td align="right">494840</td>
<td align="right">444232</td>
<td align="right">2468550</td>
</tr>
<tr>
<td height="17" align="center"><strong>Jruby</strong></td>
<td align="right" bgcolor="#e6e6e6">244040</td>
<td align="right" bgcolor="#e6e6e6">246360</td>
<td align="right" bgcolor="#e6e6e6">243830</td>
<td align="right" bgcolor="#e6e6e6">243450</td>
<td align="right" bgcolor="#e6e6e6">246750</td>
<td align="right" bgcolor="#e6e6e6">244886</td>
<td align="right" bgcolor="#e6e6e6">1224430</td>
</tr>
<tr>
<td height="17" align="center"><strong><span class="style1">PHP</span></strong></td>
<td align="right">125200</td>
<td align="right">125030</td>
<td align="right">124880</td>
<td align="right">124890</td>
<td align="right">124900</td>
<td align="right">124980</td>
<td align="right">624900</td>
</tr>
<tr>
<td height="17" align="left"></td>
<td align="left"></td>
<td align="left"></td>
<td align="left"></td>
<td align="left"></td>
<td align="left"></td>
<td align="left"></td>
<td align="left"></td>
</tr>
<tr>
<td colspan="8" height="17" align="left" valign="middle">1 segundo = 1000000 microssegundo = 1000000000 nanossegundo</td>
</tr>
</tbody>
</table>
<p>Para facilitar a visualização dos resultados, abaixo segue um gráfico com o resultado do teste:</p>
<div class="mceTemp">
<dl id="attachment_42" class="wp-caption alignnone" style="width: 638px;">
<dt class="wp-caption-dt"><a href="http://www.meupost.com/wp-content/uploads/2008/07/desempenho_linguagens.jpg"><img class="size-full wp-image-42" title="Desempenho das Linguagens de Programação" src="http://www.meupost.com/wp-content/uploads/2008/07/desempenho_linguagens.jpg" alt="Desempenho das Linguagens de Programação" width="628" height="362" /></a></dt>
</dl>
</div>
<h3>Códigos</h3>
<p>Abaixo segue os códigos utilizados nos testes. São os mesmos do var/log/mind com uma única diferença no código C++. Como o var/log/mind usou o Linux, ele usou a função <span>gettimeofday(), em Windows essa função não existe, então eu como não sou um programador C++, achei essa função no Blog <a href="http://www.openasthra.com/c-tidbits/gettimeofday-function-for-windows/">OpenAsthra</a> e coloquei no código.</span></p>
<p>Todos os outros códigos são exatamente iguais.</p>
<p>C++</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include &amp;lt;time.h&amp;gt;</span>
<span style="color: #339933;">#include &amp;lt;windows.h&amp;gt;</span>
<span style="color: #339933;">#include &amp;lt;stdio.h&amp;gt;</span>
<span style="color: #339933;">#include &amp;lt;stdlib.h&amp;gt;</span>
<span style="color: #339933;">#include &amp;lt;sys/time.h&amp;gt;</span>
&nbsp;
<span style="color: #339933;">#if defined(_MSC_VER) || defined(_MSC_EXTENSIONS)</span>
  <span style="color: #339933;">#define DELTA_EPOCH_IN_MICROSECS  11644473600000000Ui64</span>
<span style="color: #339933;">#else</span>
  <span style="color: #339933;">#define DELTA_EPOCH_IN_MICROSECS  11644473600000000ULL</span>
<span style="color: #339933;">#endif</span>
&nbsp;
<span style="color: #993333;">struct</span> timezone 
<span style="color: #009900;">&#123;</span>
  <span style="color: #993333;">int</span>  tz_minuteswest<span style="color: #339933;">;</span> <span style="color: #808080; font-style: italic;">/* minutes W of Greenwich */</span>
  <span style="color: #993333;">int</span>  tz_dsttime<span style="color: #339933;">;</span>     <span style="color: #808080; font-style: italic;">/* type of dst correction */</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">int</span> gettimeofday<span style="color: #009900;">&#40;</span><span style="color: #993333;">struct</span> timeval <span style="color: #339933;">*</span>tv<span style="color: #339933;">,</span> <span style="color: #993333;">struct</span> timezone <span style="color: #339933;">*</span>tz<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  FILETIME ft<span style="color: #339933;">;</span>
  <span style="color: #993333;">unsigned</span> __int64 tmpres <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
  <span style="color: #993333;">static</span> <span style="color: #993333;">int</span> tzflag <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>NULL <span style="color: #339933;">!=</span> tv<span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    GetSystemTimeAsFileTime<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;</span>ft<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    tmpres <span style="color: #339933;">|=</span> ft.<span style="color: #202020;">dwHighDateTime</span><span style="color: #339933;">;</span>
    tmpres <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;&amp;</span>lt<span style="color: #339933;">;=</span> <span style="color: #0000dd;">32</span><span style="color: #339933;">;</span>
    tmpres <span style="color: #339933;">|=</span> ft.<span style="color: #202020;">dwLowDateTime</span><span style="color: #339933;">;</span>
&nbsp;
    tmpres <span style="color: #339933;">/=</span> <span style="color: #0000dd;">10</span><span style="color: #339933;">;</span>  <span style="color: #808080; font-style: italic;">/*convert into microseconds*/</span>
    <span style="color: #808080; font-style: italic;">/*converting file time to unix epoch*/</span>
    tmpres <span style="color: #339933;">-=</span> DELTA_EPOCH_IN_MICROSECS<span style="color: #339933;">;</span> 
    tv<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>tv_sec <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">long</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>tmpres <span style="color: #339933;">/</span> 1000000UL<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    tv<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>tv_usec <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">long</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>tmpres <span style="color: #339933;">%</span> 1000000UL<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>NULL <span style="color: #339933;">!=</span> tz<span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>tzflag<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      _tzset<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      tzflag<span style="color: #339933;">++;</span>
    <span style="color: #009900;">&#125;</span>
    tz<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>tz_minuteswest <span style="color: #339933;">=</span> _timezone <span style="color: #339933;">/</span> <span style="color: #0000dd;">60</span><span style="color: #339933;">;</span>
    tz<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>tz_dsttime <span style="color: #339933;">=</span> _daylight<span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #339933;">#define TEST</span>
<span style="color: #339933;">#ifdef TEST</span>
<span style="color: #339933;">#endif</span>
&nbsp;
class Person
<span style="color: #009900;">&#123;</span>
&nbsp;
    public<span style="color: #339933;">:</span>
&nbsp;
        Person<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> count<span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> _next<span style="color: #009900;">&#40;</span>NULL<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> _prev<span style="color: #009900;">&#40;</span>NULL<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> _count <span style="color: #339933;">=</span> count<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
        <span style="color: #993333;">int</span> shout<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> shout<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> nth<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>shout <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> nth<span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">return</span> <span style="color: #009900;">&#40;</span>shout <span style="color: #339933;">+</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            _prev<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>_next <span style="color: #339933;">=</span> _next<span style="color: #339933;">;</span>
&nbsp;
            _next<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>_prev <span style="color: #339933;">=</span> _prev<span style="color: #339933;">;</span>
            <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #993333;">int</span> count<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">return</span> _count<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
        Person<span style="color: #339933;">*</span> next<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">return</span> _next<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
        <span style="color: #993333;">void</span> next<span style="color: #009900;">&#40;</span>Person<span style="color: #339933;">*</span> person<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> this<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>_next <span style="color: #339933;">=</span> person <span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
        Person<span style="color: #339933;">*</span> prev<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">return</span> _prev<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
        <span style="color: #993333;">void</span> prev<span style="color: #009900;">&#40;</span>Person<span style="color: #339933;">*</span> person<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> this<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>_prev <span style="color: #339933;">=</span> person<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
    private<span style="color: #339933;">:</span>
        <span style="color: #993333;">int</span> _count<span style="color: #339933;">;</span>
        Person<span style="color: #339933;">*</span> _next<span style="color: #339933;">;</span>
        Person<span style="color: #339933;">*</span> _prev<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
class Chain
<span style="color: #009900;">&#123;</span>
    public<span style="color: #339933;">:</span>
        Chain<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> size<span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> _first<span style="color: #009900;">&#40;</span>NULL<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            Person<span style="color: #339933;">*</span> current <span style="color: #339933;">=</span> NULL<span style="color: #339933;">;</span>
            Person<span style="color: #339933;">*</span> last <span style="color: #339933;">=</span> NULL<span style="color: #339933;">;</span>
            <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> i <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span> <span style="color: #339933;">;</span> i <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> size <span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
                current <span style="color: #339933;">=</span> new Person<span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>_first <span style="color: #339933;">==</span> NULL<span style="color: #009900;">&#41;</span> _first <span style="color: #339933;">=</span> current<span style="color: #339933;">;</span>
                <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>last <span style="color: #339933;">!=</span> NULL<span style="color: #009900;">&#41;</span>
                <span style="color: #009900;">&#123;</span>
                    last<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>next<span style="color: #009900;">&#40;</span>current<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    current<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>prev<span style="color: #009900;">&#40;</span>last<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
                last <span style="color: #339933;">=</span> current<span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            _first<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>prev<span style="color: #009900;">&#40;</span>last<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            last<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>next<span style="color: #009900;">&#40;</span>_first<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        Person<span style="color: #339933;">*</span> kill<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> nth<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            Person<span style="color: #339933;">*</span> current <span style="color: #339933;">=</span> _first<span style="color: #339933;">;</span>
            <span style="color: #993333;">int</span> shout <span style="color: #339933;">=</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span>current<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>next<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> current<span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
                Person<span style="color: #339933;">*</span> tmp <span style="color: #339933;">=</span> current<span style="color: #339933;">;</span>
                shout <span style="color: #339933;">=</span> current<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>shout<span style="color: #009900;">&#40;</span>shout<span style="color: #339933;">,</span>nth<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                current <span style="color: #339933;">=</span> current<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>next<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>shout <span style="color: #339933;">==</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span>
                <span style="color: #009900;">&#123;</span>
                    delete tmp<span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
            _first <span style="color: #339933;">=</span> current<span style="color: #339933;">;</span>
            <span style="color: #b1b100;">return</span> current<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        Person<span style="color: #339933;">*</span> first<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">return</span> _first<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
    private<span style="color: #339933;">:</span>
        Person<span style="color: #339933;">*</span> _first<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> argc<span style="color: #339933;">,</span> <span style="color: #993333;">char</span><span style="color: #339933;">**</span> argv<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #993333;">int</span> ITER <span style="color: #339933;">=</span> <span style="color: #0000dd;">100000</span><span style="color: #339933;">;</span>
    Chain<span style="color: #339933;">*</span> chain<span style="color: #339933;">;</span>
    <span style="color: #993333;">struct</span> timeval start<span style="color: #339933;">,</span> end<span style="color: #339933;">;</span>
    gettimeofday<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;</span>start<span style="color: #339933;">,</span>NULL<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> i <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span> <span style="color: #339933;">;</span> i <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> ITER <span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        chain <span style="color: #339933;">=</span> new Chain<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">40</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        chain<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>kill<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        delete chain<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    gettimeofday<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;</span>end<span style="color: #339933;">,</span>NULL<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    fprintf<span style="color: #009900;">&#40;</span>stdout<span style="color: #339933;">,</span><span style="color: #ff0000;">&quot;Time per iteration = %d microsecondsnr&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>end.<span style="color: #202020;">tv_sec</span> <span style="color: #339933;">-</span> start.<span style="color: #202020;">tv_sec</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #0000dd;">1000000</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>end.<span style="color: #202020;">tv_usec</span> <span style="color: #339933;">-</span> start.<span style="color: #202020;">tv_usec</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> ITER<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">//fprintf(stdout,&quot;Last man standing is %dnr&quot;, (chain-&amp;gt;first()-&amp;gt;count() + 1));</span>
    <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>JAVA:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.dnene.josephus</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Chain <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> Person first <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> Chain<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> size<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		Person last <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
		Person current <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> size<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			current <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Person<span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>first <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
				first <span style="color: #339933;">=</span> current<span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>last <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				last.<span style="color: #006633;">setNext</span><span style="color: #009900;">&#40;</span>current<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				current.<span style="color: #006633;">setPrev</span><span style="color: #009900;">&#40;</span>last<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
&nbsp;
			last <span style="color: #339933;">=</span> current<span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		first.<span style="color: #006633;">setPrev</span><span style="color: #009900;">&#40;</span>last<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		last.<span style="color: #006633;">setNext</span><span style="color: #009900;">&#40;</span>first<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> Person kill<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> nth<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		Person current <span style="color: #339933;">=</span> first<span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">int</span> shout <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>current.<span style="color: #006633;">getNext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> current<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			shout <span style="color: #339933;">=</span> current.<span style="color: #006633;">shout</span><span style="color: #009900;">&#40;</span>shout, nth<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			current <span style="color: #339933;">=</span> current.<span style="color: #006633;">getNext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		first <span style="color: #339933;">=</span> current<span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">return</span> current<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> Person getFirst<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> first<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">int</span> ITER <span style="color: #339933;">=</span> <span style="color: #cc66cc;">100000</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">long</span> start <span style="color: #339933;">=</span> <span style="color: #003399;">System</span>.<span style="color: #006633;">nanoTime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> ITER<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			Chain chain <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Chain<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">40</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			chain.<span style="color: #006633;">kill</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">long</span> end <span style="color: #339933;">=</span> <span style="color: #003399;">System</span>.<span style="color: #006633;">nanoTime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Time per iteration = &quot;</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>end <span style="color: #339933;">-</span> start<span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #009900;">&#40;</span>ITER<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
				<span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; nanoseconds.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.dnene.josephus</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Person <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">int</span> count<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> Person prev <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> Person next <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> Person<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> count<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">count</span> <span style="color: #339933;">=</span> count<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> shout<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> shout, <span style="color: #000066; font-weight: bold;">int</span> deadif<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>shout <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> deadif<span style="color: #009900;">&#41;</span>
			<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span>shout <span style="color: #339933;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">getPrev</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">setNext</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">getNext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">getNext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">setPrev</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">getPrev</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> getCount<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">count</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> Person getPrev<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> prev<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setPrev<span style="color: #009900;">&#40;</span>Person prev<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">prev</span> <span style="color: #339933;">=</span> prev<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> Person getNext<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> next<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setNext<span style="color: #009900;">&#40;</span>Person next<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">next</span> <span style="color: #339933;">=</span> next<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Ruby / JRuby</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> Person
    attr_reader <span style="color:#ff3333; font-weight:bold;">:count</span>, <span style="color:#ff3333; font-weight:bold;">:prev</span>, <span style="color:#ff3333; font-weight:bold;">:next</span>
    attr_writer <span style="color:#ff3333; font-weight:bold;">:count</span>, <span style="color:#ff3333; font-weight:bold;">:prev</span>, <span style="color:#ff3333; font-weight:bold;">:next</span>
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">def</span> initialize<span style="color:#006600; font-weight:bold;">&#40;</span>count<span style="color:#006600; font-weight:bold;">&#41;</span>
        <span style="color:#008000; font-style:italic;">#puts 'Initializing person : ' + count.to_s()</span>
        <span style="color:#0066ff; font-weight:bold;">@count</span> = count
        <span style="color:#0066ff; font-weight:bold;">@prev</span> = <span style="color:#0000FF; font-weight:bold;">nil</span>
        <span style="color:#0066ff; font-weight:bold;">@next</span> = <span style="color:#0000FF; font-weight:bold;">nil</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">def</span> shout<span style="color:#006600; font-weight:bold;">&#40;</span>shout, deadif<span style="color:#006600; font-weight:bold;">&#41;</span>
        <span style="color:#9966CC; font-weight:bold;">if</span> shout <span style="color:#006600; font-weight:bold;">&amp;</span>lt; deadif
            <span style="color:#0000FF; font-weight:bold;">return</span> shout <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#006666;">1</span>
        <span style="color:#9966CC; font-weight:bold;">end</span>
        <span style="color:#0066ff; font-weight:bold;">@prev</span>.<span style="color:#9966CC; font-weight:bold;">next</span> = <span style="color:#0066ff; font-weight:bold;">@next</span>
        <span style="color:#0066ff; font-weight:bold;">@next</span>.<span style="color:#9900CC;">prev</span> = <span style="color:#0066ff; font-weight:bold;">@prev</span>
        <span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#006666;">1</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>      
&nbsp;
<span style="color:#9966CC; font-weight:bold;">class</span> Chain
    attr_reader <span style="color:#ff3333; font-weight:bold;">:first</span>
    attr_writer <span style="color:#ff3333; font-weight:bold;">:first</span>
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">def</span> initialize<span style="color:#006600; font-weight:bold;">&#40;</span>size<span style="color:#006600; font-weight:bold;">&#41;</span>
        <span style="color:#0066ff; font-weight:bold;">@first</span> = <span style="color:#0000FF; font-weight:bold;">nil</span>
        last = <span style="color:#0000FF; font-weight:bold;">nil</span>
        <span style="color:#9966CC; font-weight:bold;">for</span> i <span style="color:#9966CC; font-weight:bold;">in</span> <span style="color:#006600; font-weight:bold;">&#40;</span>1..<span style="color:#9900CC;">size</span><span style="color:#006600; font-weight:bold;">&#41;</span>
            current = Person.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>i<span style="color:#006600; font-weight:bold;">&#41;</span>
            <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#0066ff; font-weight:bold;">@first</span> == <span style="color:#0000FF; font-weight:bold;">nil</span>
                <span style="color:#0066ff; font-weight:bold;">@first</span> = current
            <span style="color:#9966CC; font-weight:bold;">end</span>
            <span style="color:#9966CC; font-weight:bold;">if</span> last != <span style="color:#0000FF; font-weight:bold;">nil</span>
                last.<span style="color:#9966CC; font-weight:bold;">next</span> = current
                current.<span style="color:#9900CC;">prev</span> = last
            <span style="color:#9966CC; font-weight:bold;">end</span>
            last = current
        <span style="color:#9966CC; font-weight:bold;">end</span>
        <span style="color:#0066ff; font-weight:bold;">@first</span>.<span style="color:#9900CC;">prev</span> = last
        last.<span style="color:#9966CC; font-weight:bold;">next</span> = <span style="color:#0066ff; font-weight:bold;">@first</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">def</span> kill<span style="color:#006600; font-weight:bold;">&#40;</span>nth<span style="color:#006600; font-weight:bold;">&#41;</span>
        current = <span style="color:#0066ff; font-weight:bold;">@first</span>
        shout = <span style="color:#006666;">1</span>
        <span style="color:#9966CC; font-weight:bold;">while</span> current.<span style="color:#9966CC; font-weight:bold;">next</span> != current
            shout = current.<span style="color:#9900CC;">shout</span><span style="color:#006600; font-weight:bold;">&#40;</span>shout,nth<span style="color:#006600; font-weight:bold;">&#41;</span>
            current = current.<span style="color:#9966CC; font-weight:bold;">next</span>
        <span style="color:#9966CC; font-weight:bold;">end</span>
        <span style="color:#0066ff; font-weight:bold;">@first</span> = current
        <span style="color:#0000FF; font-weight:bold;">return</span> current
    <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
ITER=<span style="color:#006666;">100000</span>
start = <span style="color:#CC00FF; font-weight:bold;">Time</span>.<span style="color:#9900CC;">now</span>
ITER.<span style="color:#9900CC;">times</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>i<span style="color:#006600; font-weight:bold;">|</span>
chain = Chain.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">40</span><span style="color:#006600; font-weight:bold;">&#41;</span>
chain.<span style="color:#9900CC;">kill</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">3</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#006600; font-weight:bold;">&#125;</span>
ends = <span style="color:#CC00FF; font-weight:bold;">Time</span>.<span style="color:#9900CC;">now</span>
<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">'Time per iteration = '</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#40;</span>ends <span style="color:#006600; font-weight:bold;">-</span> start<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">*</span> <span style="color:#006666;">1000000</span> <span style="color:#006600; font-weight:bold;">/</span> ITER<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">to_s</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">&quot; microseconds&quot;</span></pre></div></div>

<p>PHP</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>?php
<span style="color: #000000; font-weight: bold;">class</span> Person
<span style="color: #009900;">&#123;</span>   
    <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #000088;">$c</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>   
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>count <span style="color: #339933;">=</span> <span style="color: #000088;">$c</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>       
&nbsp;
    <span style="color: #000000; font-weight: bold;">function</span> getPrev<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>       
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>prev<span style="color: #339933;">;</span> 
    <span style="color: #009900;">&#125;</span>           
&nbsp;
    <span style="color: #000000; font-weight: bold;">function</span> setPrev<span style="color: #009900;">&#40;</span><span style="color: #000088;">$pr</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>   
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>prev <span style="color: #339933;">=</span> <span style="color: #000088;">$pr</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>   
&nbsp;
    <span style="color: #000000; font-weight: bold;">function</span> getNext<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>next<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">function</span> setNext<span style="color: #009900;">&#40;</span><span style="color: #000088;">$nxt</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>next <span style="color: #339933;">=</span> <span style="color: #000088;">$nxt</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">function</span> shout<span style="color: #009900;">&#40;</span><span style="color: #000088;">$shout</span><span style="color: #339933;">,</span> <span style="color: #000088;">$nth</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$shout</span> <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> <span style="color: #000088;">$nth</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">return</span> <span style="color: #000088;">$shout</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>getPrev<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>setNext<span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>getNext<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>getNext<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>setPrev<span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>getPrev<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> Chain
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$first</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #000088;">$size</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> <span style="color: #000088;">$size</span> <span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$current</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Person<span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>first <span style="color: #339933;">==</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>first <span style="color: #339933;">=</span> <span style="color: #000088;">$current</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$last</span> <span style="color: #339933;">!=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$last</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>setNext<span style="color: #009900;">&#40;</span><span style="color: #000088;">$current</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000088;">$current</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>setPrev<span style="color: #009900;">&#40;</span><span style="color: #000088;">$last</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #000088;">$last</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$current</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>first<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>setPrev<span style="color: #009900;">&#40;</span><span style="color: #000088;">$last</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$last</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>setNext<span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>first<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">function</span> kill<span style="color: #009900;">&#40;</span><span style="color: #000088;">$nth</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$current</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>first<span style="color: #339933;">;</span>
        <span style="color: #000088;">$shout</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$current</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>getNext<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!==</span> <span style="color: #000088;">$current</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$shout</span> <span style="color: #339933;">=</span>  <span style="color: #000088;">$current</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>shout<span style="color: #009900;">&#40;</span><span style="color: #000088;">$shout</span><span style="color: #339933;">,</span><span style="color: #000088;">$nth</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$current</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$current</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>getNext<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>first <span style="color: #339933;">=</span> <span style="color: #000088;">$current</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$start</span> <span style="color: #339933;">=</span> <span style="color: #990000;">microtime</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$ITER</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">100000</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span> <span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> <span style="color: #000088;">$ITER</span> <span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$chain</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Chain<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">40</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$chain</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>kill<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000088;">$end</span> <span style="color: #339933;">=</span> <span style="color: #990000;">microtime</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Time per iteration = <span style="color: #009933; font-weight: bold;">%3.2f</span> microsecondsnr&quot;</span><span style="color: #339933;">,</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$end</span> <span style="color: #339933;">-</span>  <span style="color: #000088;">$start</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">100000</span> <span style="color: #339933;">/</span> <span style="color: #000088;">$ITER</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
?<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span></pre></div></div>

<p>É isso pessoal.</p>
<p>Esse tema de desempenho sempre gera polêmica pois sempre há brechas e margens para discussão. Então, quem quiser debater sobre o assunto.</p>
<p>Até a próxima.</p>
</div>

<p>Related posts:<ol><li><a href='http://www.meupost.com/2008/11/18/fatorial-recursivo-em-java-e-ruby/' rel='bookmark' title='Permanent Link: Fatorial recursivo em Java e Ruby'>Fatorial recursivo em Java e Ruby</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.meupost.com/2008/07/27/comparacao-de-desempenho-entre-linguagens-de-programacao/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
