This is a benchmark for https://wiki.php.net/rfc/friend-classes that attempts to approximate performance delta between master
and feature/friend-classes-poc
.
Both benchmarks execute a script that attempts access of a target property 100,000 times. We sample 100 executions of this script and average to compare.
Compilation
make clean
make distclean
./vcsrepo
./buildconf
./configure --enable-cli --enable-debug
make -j9
As this is functionality that doesn't exist, we can only compare difference in property access (in the worst case) as well as clock time to parse / manage "friend" data on zend_class_entry
.
The following script is executed to measure access time for a public
property.
<?php
class Readable {
public $property = 'foo';
}
class Reader {
public function read(Readable $object) {
$foo = $object->property;
}
}
$readable = new Readable();
$reader = new Reader();
// Time the following...
$start = microtime();
for ($i = 0; $i < 100000; $i++) {
$reader->read($readable);
}
echo (microtime() - $start) . PHP_EOL;
This is master
running for n in {1..100}; do sapi/cli/php ~/control.php; done
.
Average: 0.01874479592 seconds
We are timing protected
access for a friend
class as well as time it takes to attach "friend" data to NotReadable
's zend_class_entry
.
<?php
class NotReadable {
friend Reader;
protected $property = 'foo';
}
class Reader {
public function read(NotReadable $object) {
$foo = $object->property;
}
}
$not_readable = new NotReadable();
$reader = new Reader();
// Time the following...
$start = microtime();
for ($i = 0; $i < 100000; $i++) {
$reader->read($not_readable);
}
echo (microtime() - $start) . PHP_EOL;
This is feature/friend-classes-poc
running for n in {1..100}; do sapi/cli/php ~/experiment.php; done
.
Average: 0.01917070103 seconds
There is a 0.000425905 difference in runtime (experiment slower). Given the small sample size for this benchmark, I would claim "no noticeable difference" in performance between the two branches.