duanbipu1720 2013-11-20 03:46
浏览 35

一般性能优化

I am writing a function that returns an array of values to the caller. Let's say the array is:

$arr['keyN'] = $valueN;

If any '$keyN' does not have a value; its value is entered as zero.

My question is purely from a performance point of view: Is it better to give the key a value of zero or to NOT GIVE IT ANY VALUE AT ALL and have the caller test its presence if(isset($arr[$keyN]))....then execute code?

The reason I am asking this is because giving the array key a zero value will consume main memory and testing its existence will consume CPU cycles. So would it be better to take up some memory space (with a zero value) or not assign anything to the key and have the code test for its existence?

  • 写回答

2条回答 默认 最新

  • dongzhanlu0658 2013-11-20 03:57
    关注

    I think it's better not to assign nothing, so the value will be NULL, what means that no value is stored to that variable in the "simbolic table". PHP allocates memory in a dinamic fashion, unlike in C, that you would have a memory "block", even if it's useless.

    Here I give you a starting link for the reading: http://www.php.net/manual/pt_BR/internals2.variables.intro.php

    评论

报告相同问题?

悬赏问题

  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch