Benchmark: dirname(__FILE__) vs __DIR__ in PHP
dirname(__FILE__) and __DIR__ give exactly the same result in PHP, although one (__DIR__) is evaluated at compile-time, while the other (dirname(__FILE__)) has at least part of it (the function) evaluated at execution time.
Ever wondered what the difference is, in terms of efficiency, between the two? I've written a *very* simple script to try it out:
<?php $loops = 100000000; echo 'Testing dirname(__FILE__)' . PHP_EOL; $start = time(); $dir = ''; for ($i = 0; $i < $loops; $i++) { $dir = dirname(__FILE__); } echo 'dirname(__FILE__) took ' . (time()-$start) . 's' .