note 114559 added to language.oop5.typehinting

From: Date: Thu, 06 Mar 2014 09:16:06 +0000
Subject: note 114559 added to language.oop5.typehinting
Groups: php.notes 
Request: Send a blank email to php-notes+get-198811@lists.php.net to get a copy of this message
I've done some tests of the overhead that class Typehint gives us. At my PC it goes as follows: teststringNormal took: 0.041965961456299 teststringOverhead took: 0.48374915122986 It's like 10x longer time (not mention about memory usage), it's just because exception is thrown EVERY SINGLE TIME, along with expensive preg_match() and debug_backtrace() calls. I think that using class in bigger applications will increase overhead like 100% or more. <?php function teststringOverhead(string $string) { return $string; } function teststringNormal($string){ if(!is_string($string)){ return; } return $string; } $loopTimes = 20000; /////////// test of overhead implementation vs normal $t1 = microtime(true); for($i = 0; $i <= $loopTimes; $i++) teststringNormal("xxx"); echo "<br>teststringNormal took: " . (microtime(true) - $t1); $t2 = microtime(true); for($i = 0; $i <= $loopTimes; $i++) teststringOverhead("xxx"); echo "<br>teststringOverhead took: " . (microtime(true) - $t2); ?> ---- Server IP: 72.52.91.14 Probable Submitter: 72.52.91.14 ---- Manual Page -- http://php.net/manual/en/language.oop5.typehinting.php Edit -- https://master.php.net/note/edit/114559 Del: integrated -- https://master.php.net/note/delete/114559/integrated Del: useless -- https://master.php.net/note/delete/114559/useless Del: bad code -- https://master.php.net/note/delete/114559/bad+code Del: spam -- https://master.php.net/note/delete/114559/spam Del: non-english -- https://master.php.net/note/delete/114559/non-english Del: in docs -- https://master.php.net/note/delete/114559/in+docs Del: other reasons-- https://master.php.net/note/delete/114559 Reject -- https://master.php.net/note/reject/114559 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#198811) next »