3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Person { function __construct($c) { $this->count = $c; } function getPrev() { return $this->prev; } function setPrev($pr) { $this->prev = $pr; } function getNext() { return $this->next; } function setNext($nxt) { $this->next = $nxt; } function shout($shout, $nth) { if ($shout < $nth) { return $shout + 1; } $this->getPrev()->setNext($this->getNext()); $this->getNext()->setPrev($this->getPrev()); return 1; } } class Chain { var $first; function __construct($size) { $last =null; for($i = 0; $i < $size ; $i++) { $current = new Person($i); if ($this->first == null) $this->first = $current; if ($last != null) { $last->setNext($current); $current->setPrev($last); } $last = $current; } $this->first->setPrev($last); $last->setNext($this->first); } function kill($nth) { $current = $this->first; $shout = 1; while($current->getNext() !== $current) { $shout = $current->shout($shout,$nth); $current = $current->getNext(); } $this->first = $current; } } $start = microtime(true); $ITER = 1000; for($i = 0 ; $i < $ITER ; $i++) { $chain = new Chain(40); $chain->kill(3); } $end = microtime(true); printf("Time per iteration = %3.2f microsecondsnr",(($end - $start) * 1000 / $ITER));

preferences:
31.24 ms | 402 KiB | 5 Q