note 99216 modified in language.operators.comparison by felipe

From: Date: Thu, 05 Aug 2010 01:24:22 +0000
Subject: note 99216 modified in language.operators.comparison by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-171373@lists.php.net to get a copy of this message
I prefer writing (!$a == 'hello') much more than ($a != 'hello'), but I wondered about the performance. So I did a benchmark: <?php for($bench = 0; $bench < 3; $bench++) { $start = microtime(true); $a = 1; for($i = 0; $i < 100000000; $i++) { if(!$a == 'hello') $b++; } $end = microtime(true); echo "Used time: " . ($end-$start) . "\n"; } ?> and it results with # if($a != 'hello') Used time: 12.552895069122 Used time: 12.548940896988 Used time: 12.470285177231 # if(!$a == 'hello') Used time: 7.6532161235809 Used time: 7.6426539421082 Used time: 7.6452689170837 --was-- I prefer writing (!$a == 'hello') much more than ($a != 'hello'), but I wondered about the performance. So I did a benchmark: for($bench = 0; $bench < 3; $bench++) { $start = microtime(true); $a = 1; for($i = 0; $i < 100000000; $i++) { if(!$a == 'hello') $b++; } $end = microtime(true); echo "Used time: " . ($end-$start) . "\n"; } and it results with # if($a != 'hello') Used time: 12.552895069122 Used time: 12.548940896988 Used time: 12.470285177231 # if(!$a == 'hello') Used time: 7.6532161235809 Used time: 7.6426539421082 Used time: 7.6452689170837 http://php.net/manual/en/language.operators.comparison.php

« previous php.notes (#171373) next »