Jump to content

which is fastest?


Fyorl

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.
Link to comment
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.
Link to comment
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]
Link to comment
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?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.