How efficient is define in PHP?

前端 未结 10 1394
不思量自难忘°
不思量自难忘° 2020-12-15 18:38

C++ preprocessor #define is totally different.

Is the PHP define() any different than just creating a var?

define(\"SETTING         


        
10条回答
  •  别那么骄傲
    2020-12-15 19:07

    'define' operation itself is rather slow - confirmed by xdebug profiler.

    Here is benchmarks from http://t3.dotgnu.info/blog/php/my-first-php-extension.html:

    • pure 'define'
      380.785 fetches/sec
      14.2647 mean msecs/first-response

    • constants defined with 'hidef' extension
      930.783 fetches/sec
      6.30279 mean msecs/first-response


    broken link update

    The blog post referenced above has left the internet. It can still be viewed here via Wayback Machine. Here is another similar article.

    The libraries the author references can be found here (apc_define_constants) and here (hidef extension).

提交回复
热议问题