Numeric arrays revisited

at 2005-06-12 in General by kiesel (0 comments)

In Numeric arrays Timm has compared various array access methods in regard to their speed for quite a common task.

While that was really interesting and certainly will have affect on the different connectors we have to other languages (SOAP, xmlrpc, ...), I missed one special method: the fastest :)

Not surprisingly, the fastest array access can be done in PHP's native language C. However, standard PHP does not have exactly the method we need, so I took it as an exercise, programmed one, and called it array_is_numeric() (see the implementation in this patch).

After compiling PHP (it's PHP4_4 from CVS), I added a new strategy to Timm's isnumeric.php:

#6: Use native array access

<?php 
class BuiltinStrategy extends Object {

function execute($a) {
return array_is_numeric
($a);
}
}
?>


Not suprisingly, the native array access strategy outperforms all others, no matter what size the array to check really is.

See the detailled test results here.

PS: This does not only prove that C is faster than PHP, but also another thing: my machine is faster than Timm's ;)



Subscribe

You can subscribe to the XP framework's news by using RSS syndication.


Categories

News
General
PHP5
Announcements
RFCs
Further reading
Examples
Editorial
EASC
Experiments
Unittests
Databases

Related

Find related articles by a search for «Numeric».