note 83910 deleted from function.abs by hholzgra

From: Date: Sun, 15 Apr 2012 19:29:50 +0000
Subject: note 83910 deleted from function.abs by hholzgra
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-187149@lists.php.net to get a copy of this message
Note Submitter: zyphos at zyphos dot be ---- I think there are faster methods for doing an on/off. $value = (1 - $value); or better: $value = (1 ^ $value); // which uses the xor function. Below are the benchs on my computer, for loop of 10,000,000 with PHP Version 5.2.1 $value = abs($value -1); // 4.12641406059 sec $value = (1 - $value); // 1.58847904205 sec $value = (1 ^ $value); // 1.49518704414 sec Note that using function call for such operation is very slow. function on_off($value) { return (1 ^ $value); } // 7.10739612579 sec

« previous php.notes (#187149) next »