问题描述
我有一个网站,该网站使用很多这样定义的常量,例如:
I have a website which uses a lot of constants, that are defined like this, for example:
define('CONSTANT', 1)
我目前有大约200个这样的定义的列表.每次页面加载时都会运行此列表.这会严重影响我的性能或内存使用吗?
I currently have a list of about 200 defines like this. This list is run every time a page loads. Is this going to affect my performance or memory use badly?
推荐答案
有理由避免在每次页面加载时列出200个常量,但是性能和内存使用情况就不在其中.通常,回答此类问题的最佳方法是运行基准测试.在加载和不加载200个常量的情况下,测量页面加载时间和内存使用情况.测量数千次,然后看数字.我怀疑您会发现微不足道的差异.微观优化通常是在浪费时间.
There are reasons to avoid a list of 200 constants on every page load, but performance and memory usage would not be among them. In general, the best way to answer these kinds of questions is to run benchmarks. Measure page load time and memory usage both with and without loading your 200 constants. Measure a few thousand times and look at the numbers. I suspect you'll find a negligible difference. Micro-optimization is usually a waste of time.
这篇关于定义很多常量会导致性能或内存问题吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!