note 73651 deleted from function.settype by danbrown
| From: | danbrown@php.net | Date: | Sat, 02 Feb 2013 15:15:43 +0000 |
| Subject: | note 73651 deleted from function.settype by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-193505@lists.php.net to get a copy of this message | ||
Note Submitter: sneskid at hotmail dot com
----
In response to the guy who was having troubles with leading zeros and wrote the convertToInt
function.
I benchmarked it and it is faster to just use base_convert than ltrim & friends.
base_convert also has a lower "first time call" cost than ltrim (this could be related to
server settings).
It's about 2/3 that of ltrim.
If you only use this type of conversion once per script then it's far more beneficial to use
base_convert.
The average values listed are ignoring the first time call costs.
<?php
$t = '0100';
// avg: 0.0000025 (0.0000036 wrapped as a function)
$x = base_convert($t, 10, 10);
// avg: 0.0000028 (0.0000039 wrapped as a function)
$x = 0+ltrim($t,'0');
?>