Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $initial = 5;
- $unit = 10;
- $operation = '+';
- function add($a, $b) { return $a + $b; }
- function sub($a, $b) { return $a - $b; }
- $operations = array('+' => 'add', '-' => 'sub');
- $count = 100000;
- $start = microtime(true);
- for($i = 0; $i < $count; $i++)
- $operations[$operation]($initial, $unit);
- $end = microtime(true);
- echo "took " . number_format((($end - $start)/$count), 15) . " microseconds\n";
- $start = microtime(true);
- $str = "return $initial $operation $unit;";
- for($i = 0; $i < $count; $i++)
- eval($str);
- $end = microtime(true);
- echo "took " . number_format((($end - $start)/$count), 15) . " microseconds\n";
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement