Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- define('NUM_EXECUTIONS', 100000);
- function timeFunc($function, $runs)
- {
- $times = array();
- for ($i = 0; $i < $runs; $i++)
- {
- $time = microtime();
- call_user_func($function);
- $times[$i] = microtime() - $time;
- }
- return array_sum($times) / $runs;
- }
- function Method1()
- {
- $foo = 'some words';
- for ($i = 0; $i < NUM_EXECUTIONS; $i++)
- $t = "these are 1";
- }
- function Method2()
- {
- $foo = 'some words';
- for ($i = 0; $i < NUM_EXECUTIONS; $i++)
- $t = "these are " . $foo;
- }
- function Method3()
- {
- $foo = 'some words';
- for ($i = 0; $i < NUM_EXECUTIONS; $i++)
- $t = "these are $foo";
- }
- function Method4()
- {
- $foo = 'some words';
- for ($i = 0; $i < NUM_EXECUTIONS; $i++)
- $t = "these are {$foo}";
- }
- print timeFunc('Method1', 10) . "\n";
- print timeFunc('Method2', 10) . "\n";
- print timeFunc('Method3', 10) . "\n";
- print timeFunc('Method4', 10) . "\n";
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement