Fyorl Posted June 7, 2006 Share Posted June 7, 2006 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 https://forums.phpfreaks.com/topic/11445-which-is-fastest/ Share on other sites More sharing options...
xyph Posted June 7, 2006 Share Posted June 7, 2006 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 https://forums.phpfreaks.com/topic/11445-which-is-fastest/#findComment-42972 Share on other sites More sharing options...
poirot Posted June 7, 2006 Share Posted June 7, 2006 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 https://forums.phpfreaks.com/topic/11445-which-is-fastest/#findComment-42981 Share on other sites More sharing options...
xyph Posted June 7, 2006 Share Posted June 7, 2006 Remember to do the testing on a large scale, otherwise the results will be useless. Link to comment https://forums.phpfreaks.com/topic/11445-which-is-fastest/#findComment-42987 Share on other sites More sharing options...
Fyorl Posted June 8, 2006 Author Share Posted June 8, 2006 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 https://forums.phpfreaks.com/topic/11445-which-is-fastest/#findComment-43286 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.