Created
August 4, 2015 00:59
-
-
Save slav123/29ba4947a3ceacd37cb4 to your computer and use it in GitHub Desktop.
benchmark
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $data = 'a:9:{i:0;a:2:{s:7:"step_id";s:1:"1";s:9:"step_name";s:8:"Strategy";}i:1;a:2:{s:7:"step_id";s:1:"2";s:9:"step_name";s:9:"Structure";}i:2;a:2:{s:7:"step_id";s:1:"3";s:9:"step_name";s:7:"Finance";}i:3;a:2:{s:7:"step_id";s:1:"4";s:9:"step_name";s:14:"Buyer Advocacy";}i:4;a:2:{s:7:"step_id";s:1:"5";s:9:"step_name";s:24:"Renovation & Development";}i:5;a:2:{s:7:"step_id";s:1:"6";s:9:"step_name";s:19:"Property Management";}i:6;a:2:{s:7:"step_id";s:1:"7";s:9:"step_name";s:16:"Portfolio Review";}i:7;a:2:{s:7:"step_id";s:1:"8";s:9:"step_name";s:14:"Sales Advisory";}i:8;a:2:{s:7:"step_id";s:1:"9";s:9:"step_name";s:9:"Valuation";}}'; | |
| function make_assoc(&$input_array, $pkey = 'id', $sort = FALSE) | |
| { | |
| $keys = array_column($input_array, $pkey); | |
| $input_array = array_combine($keys, $input_array); | |
| } | |
| $steps = unserialize($data); | |
| function f1($steps) { | |
| make_assoc($steps, 'step_id'); | |
| $steps = array_map(function ($row) | |
| { | |
| return $row['step_name']; | |
| }, $steps); | |
| } | |
| function f2($steps) { | |
| $return = array(); | |
| foreach ($steps as $row) { | |
| $return[$row['step_id']] = $row['step_name']; | |
| } | |
| } | |
| function f3($steps) { | |
| $return = array(); | |
| for ($a = 0,$max=count($steps);$a<$max;$a++) { | |
| $return[$steps[$a]['step_id']] = $steps[$a]['step_name']; | |
| } | |
| } | |
| $start = microtime(true); | |
| f1($steps); | |
| $stop = microtime(true); | |
| $time1 = $stop - $start; | |
| echo $time1; | |
| $start = microtime(true); | |
| f2($steps); | |
| $stop = microtime(true); | |
| $time2 = $stop - $start; | |
| echo "\n"; | |
| echo $time2; | |
| $start = microtime(true); | |
| f3($steps); | |
| $stop = microtime(true); | |
| $time3 = $stop - $start; | |
| echo "\n"; | |
| echo $time3; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment