Skip to content

Instantly share code, notes, and snippets.

@ak4n
ak4n / foreach_vs_array_asterix
Last active December 20, 2018 13:00
Benchmarking execution time of PHP constructs (list / each, foreach) vs (array_walk, array_map, array_reduce, array_filter)
<?php
/**
* Execution time check for: (list/each,foreach) vs (array_walk, array_map, array_reduce, array_filter)
* @docs to read
* http://www.giorgiosironi.com/2010/02/stop-writing-foreach-cycles.html
* http://www.pastie.org/829318
* http://php.net/manual/en/function.array-walk.php#112722
* http://zaemis.blogspot.com/2013/06/building-array-with-arrayreduce.html
* (!) http://stackoverflow.com/questions/2473989/list-of-big-o-for-php-functions/2484455#2484455
* http://www.faieta.net/wp/performance-implications-of-closures-in-php/
86937 isset
43159 echo
31697 empty
29252 substr
26146 count
24248 is_array
22572 strlen
19365 sprintf
18090 unset
16584 str_replace