Warning: Division by zero in /var/customers/webs/stc/benchmark/index.php on line 256 Test: function vs. class method

PHP Benchmarks

Performance comparison of PHP code alternatives.

Test: function vs. class method

Tests for any difference between calling a free function or a member function.

Run Again Test Menu

Result

Unfortunately, no history for this test is available.

Code

The first test, "class method", was:

/*
class Example
{
	var $x;

	function foo()
	{
		$this->x = 42;

		return 42;
	}
}
*/

$test = new Example();

for ($i = 0; $i < 100; $i++)
	$GLOBALS['dummy'] = $test->foo();

The second test, "function", was:

/*
function example_foo(&$array)
{
	$array['x'] = 42;

	return 42;
}
*/

$test = array();

for ($i = 0; $i < 100; $i++)
	$GLOBALS['dummy'] = example_foo($test);

Running: Linux (x86_64:1 GB) PHP (7.2.25-1+ubuntu16.04.1+deb.sury.org+1)