php - 比较两个 DateTime 对象的 PHP 性能负载
问题描述
我有一个可用性类,它会进行许多检查以查看日期是否可用,但其中一项检查是查看可预订产品是否在预订窗口内(即将来足以满足用户当天预订的标准) . 代码如下 -
private function set_within_booking_window(){
$timezone = get_option('timezone_string');
$starttime = cb_get_product_starttime($this->product_id, $this->date);
$this->starttime = $starttime;
//get booking window
$window = new DateTime();
$window->setTimezone(new DateTimeZone($timezone));
$buffer = get_option("cb_same_day_buffer");
$window->add(new DateInterval("PT".$buffer."H"));
$this->window = $window;
if($starttime < $window){
$this->within_booking_window = false;
} else {
$this->within_booking_window = true;
}
}
在性能研究中,除了 if($starttime < $window) 的 DateTime 比较之外,整个操作构建良好且速度很快,这基本上会杀死整个可用性类的性能。页面加载不到 1 秒,该表达式被注释掉,超过 26 秒。
我在 PHP 文档中读到的所有内容都表明这是比较两个日期时间的最佳方法 - 但这不可能是正确的......
比较两个 PHP DateTime 对象时有任何关于性能的反馈吗?
解决方案
推荐阅读
- javascript - 从 Ajax 成功加载所有数据后,我想使用另一个 ajax 来更改图像 loading.gif
- ios - Swift :- 线程 1:致命错误:余数或除以零
- twitter-bootstrap - Bootstrap 4 导航栏,带有品牌中心和左侧、中心和右侧的链接
- r - plotly R条形图更新直接标签数据
- orchardcms - ContentPartRecord 和常规 MVC 模型对象有什么区别?
- ios - 关闭应用程序时,Xamarin iOS 保存在领域数据库上
- python - 线性回归模型:为什么我的测试分数高于我的训练分数?
- java - 如何将此 Python 代码转换为 Java?
- c - 保证指向标准函数的指针不相等?
- c++ - 静态函数的单例类 dlopen 错误(无法在示例代码中重现)!