note 98760 deleted from function.eval by danbrown

From: Date: Tue, 06 Jul 2010 13:22:59 +0000
Subject: note 98760 deleted from function.eval by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-170735@lists.php.net to get a copy of this message
Note Submitter: robert dot turnbull at hotmail dot com ---- I was curious about plain code versus eval versus include, so I wrote the following script. Based on my results, it seems as though eval is the slowest method of the three, even though previous comments indicate otherwise. <?php /* Results Test #1: Plain Code Results: 0.0162778673172 Test #2: eval'd code Results: 0.0177816636562 Test #3: Included code Results: 0.0167677741051 */ echo "Test #1: Plain Code<br />"; $totalTime = 0; $totalAttempts = 0; for ($j = 0; $j < 1000; $j++) { $start = microtime(true); $i = 0; for ($k = 0; $k < 100000; $k++) { $i++; } $end = microtime(true); $elapsed = $end - $start; $totalTime += $elapsed; $totalAttempts++; } echo "Results: " . ($totalTime / $totalAttempts) . "<br />"; echo "Test #2: eval'd code<br />"; $totalTime = 0; $totalAttempts = 0; for ($j = 0; $j < 1000; $j++) { $start = microtime(true); eval('$i = 0; for ($k = 0; $k < 100000; $k++) { $i++; }'); $end = microtime(true); $elapsed = $end - $start; $totalTime += $elapsed; $totalAttempts++; } echo "Results: " . ($totalTime / $totalAttempts) . "<br />"; echo "Test #3: Included code<br />"; $totalTime = 0; $totalAttempts = 0; for ($j = 0; $j < 1000; $j++) { $start = microtime(true); include("evalme.php"); $end = microtime(true); $elapsed = $end - $start; $totalTime += $elapsed; $totalAttempts++; } echo "Results: " . ($totalTime / $totalAttempts) . "<br />"; ?> evalme.php <?php $i = 0; for ($k = 0; $k < 100000; $k++) { $i++; } ?>

« previous php.notes (#170735) next »