Jump to content

Archived

This topic is now archived and is closed to further replies.

Fyorl

which is fastest?

Recommended Posts

I was just wondering if anyone was in a good position to test whether [code]func_num_args()[/code] is faster than [code]count(func_get_args())[/code]

(They come in very useful for creating functions with default values)
Anyway, I would assume the former as it's only one function call but I could be wrong as I don't know the inner workings of it.

Share this post


Link to post
Share on other sites
My guess would be in agreement with yours...

The 2nd function you're building an array simply to count it. Could be wrong though.

I doubt the difference in speed would be huge unless dealing with a very very large function.

Share this post


Link to post
Share on other sites
I guess func_num_args() is faster. It's just a guess though.
You can test that by yourself, just time it like this:

[code]$time1 = microtime(true);
// Do method1 here
$time2 = microtime(true);
// Do method2 here
$time3 = microtime(true);

echo 'Method 1: ' . ($time2 - $time1);
echo 'Method 2: ' . ($time3 - $time2);[/code]

Share this post


Link to post
Share on other sites
Remember to do the testing on a large scale, otherwise the results will be useless.

Share this post


Link to post
Share on other sites
Thanks guys, I've got a PHP 4 server and PHP 5 on my linux laptop so I'll do a test on there. Just one question, wouldn't testing on a 'large scale' involve passing many, many arguments to a function?

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.