Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question<?php class Node { private $childNodes; private $data; public function __construct($data) { $this->data = (string)$data; $this->childNodes = array(); } public function display() { echo $this->data, PHP_EOL; foreach ($this->childNodes as $child) $child->display(); } public function addChild(Node $child) { $this->childNodes[] = $child; } public function getNChild($n) { if (!is_int($n)) throw new Exception('whatever'); if ($n < 0 || $n >= sizeof($this->childNodes)) throw new Exception('whatever bis'); return $this->childNodes[$n]; } } $root = new Node('Root'); $root->addChild(new Node('toto')); $root->addChild(new Node('titi')); $root->addChild(new Node('tutu')); $root->getNChild(1)->addChild(new Node('plop')); $root->display(); ?>
#include #include <vector> class Node { private: std::string _data; std::vector<Node> _childNodes; Node() {}; public: Node(const std::string data) { _data += data; }; Node(const Node &cp) { if (&cp != this) *this = cp; }; ~Node() {}; Node &operator=(const Node &r) { _data = r._data; _childNodes = r._childNodes; return *this; }; void display() { std::cout << _data << std::endl; for (unsigned int i = 0; i < _childNodes.size(); i++) _childNodes[i].display(); }; void addChild(const Node &child) { _childNodes.push_back(child); }; void addChild(const Node *child) { _childNodes.push_back(*child); }; Node &getNChild(unsigned int n) { if (n >= _childNodes.size()) throw std::exception(); return _childNodes[n]; }; }; int main() { Node root("Root"); root.addChild(new Node("toto")); root.addChild(new Node("titi")); root.addChild(new Node("tutu")); root.getNChild(1).addChild(new Node("plop"));; root.display(); return 0; }
tycho@uraniborg-> g++ plop.cpp tycho@uraniborg-> time ./a.out >/dev/null real 0m0.005s user 0m0.000s sys 0m0.004s tycho@uraniborg-> time php plop.php >/dev/null real 0m0.103s user 0m0.068s sys 0m0.028s
tycho@uraniborg-> g++ plop.cpp tycho@uraniborg-> time ./a.out >/dev/null real 0m0.008s user 0m0.008s sys 0m0.000s tycho@uraniborg-> time php plop.php >/dev/null real 0m0.132s user 0m0.112s sys 0m0.012s
Je veux éviter ça lorsque je bosse, connaitre ce qu'il faut pour ne pas me retrouver avec un code que je dois retravailler par couches en direct sur le serveur prod.
PHP c'est vraiment lent...
Personnelement moi j'ai bossé sur un site qui accueille 3000 visites/jour mais comparé à Meetic ou Netlog j'ai bossé sur un petit site :P
Donc très bonne question.