Intro A list of micro-optimization tests / benchmarks. No guessing - just code and results. See testing page if you want to know the details of how each micro-optimization was tested. Add new code for the comparison - the tests will be run shortly.
Increment with foreach() and range() vs for() Submitted by darraghenright on Wed, 02/13/2013 - 22:28 f1 is slower than f2 by 0% 50% updown50%
is_a / instanceof Submitted by arney on Fri, 01/04/2013 - 22:56 f1 is slower than f2 by 0% 50% updown50%
strtr() vs str_replace() Submitted by mattg on Wed, 11/14/2012 - 10:51 f2 is slower than f1 by 9.76% 50% updown50%
closure vs. create_function Submitted by pholden on Tue, 11/13/2012 - 11:16 f2 is slower than f1 by 104.93% (1 times slower)50% updown50%
preg_split vs explode Submitted by Ouroboros on Sun, 11/11/2012 - 17:26 f1 is slower than f2 by 45.68% 50% updown50%
array_merge vs foreach (with numeric keys) Submitted by Lito on Wed, 08/08/2012 - 13:21 f1 is slower than f2 by 85.06% 100% updown0%
string concatenation (with double quotes) vs sprintf Submitted by hett on Fri, 08/03/2012 - 15:01 f2 is slower than f1 by 138.68% (1.4 times slower)50% updown50%
string concatenation (with single quotes) vs sprintf Submitted by hett on Fri, 08/03/2012 - 14:59 f2 is slower than f1 by 163.72% (1.6 times slower)50% updown50%
array_map with anonymous function vs convoluted example Submitted by darraghenright on Thu, 06/07/2012 - 10:16 f1 is slower than f2 by 65.55% 50% updown50%
is_a vs instanceof Submitted by gekkie on Tue, 05/15/2012 - 15:25 f1 is slower than f2 by 195.31% (2 times slower)50% updown50%
Use empty function or direct comparison (with undefined variable) Submitted by Lito on Tue, 03/27/2012 - 12:48 f2 is slower than f1 by 427.98% (4.3 times slower)100% updown0%
Use empty function or direct comparison (with defined variable) Submitted by Lito on Tue, 03/27/2012 - 12:41 f1 is slower than f2 by 0.84% 50% updown50%
str_replace vs implode explode Submitted by kgruszczynski on Thu, 03/22/2012 - 00:40 f1 is slower than f2 by 135.91% (1.4 times slower)50% updown50%
str_replace vs preg_replace (without regular expression) Submitted by Lito on Fri, 03/16/2012 - 15:48 f2 is slower than f1 by 61.56% 50% updown50%
file_exists vs is_file (existing files with error ignore) Submitted by Lito on Fri, 03/16/2012 - 15:45 f1 is slower than f2 by 232.94% (2.3 times slower)50% updown50%
file_exists vs is_file (non existing files) Submitted by Lito on Fri, 03/16/2012 - 15:43 f1 is slower than f2 by 53.52% 50% updown50%
file_exists vs is_file (existing files) Submitted by Lito on Fri, 03/16/2012 - 15:38 f1 is slower than f2 by 371.63% (3.7 times slower)50% updown50%
Extended if vs short if Submitted by Lito on Fri, 03/16/2012 - 15:31 f2 is slower than f1 by 7.11% 50% updown50%