【问题标题】:Timing my php function with using Result cache and without result cache使用结果缓存和不使用结果缓存来计时我的 php 函数
【发布时间】:2016-06-22 03:31:27
【问题描述】:

我一直在尝试测量我的一个 php 函数在使用结果缓存和不使用结果缓存时所花费的时间。

我遇到了麻烦,因为无论哪个在结果中先运行都会给更多时间,因此结果不是决定性的。

这是我的代码的一部分 -

     /**
     *
     * @param InputInterface $input
     * @param OutputInterface $output
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
//        $this->withoutCache($output);
        $this->withCache($output);
        $this->withoutCache($output);
    }

输出 -

RUN 1 - 
withoutCache: 0.10952067375183
withCache: 0.077319145202637

RUN 2 - 
withCache: 0.17031812667847
withoutCache: 0.042220115661621

我正在使用 symfony 框架,我正在测试使用缓存是否会在每次查询时对我有很大帮助。 Symfony 使用 Doctrine ORM 和 redis 作为结果缓存。

【问题讨论】:

    标签: php symfony redis doctrine profiling


    【解决方案1】:

    您可能正在初始化一些对象或做一些与实际过程无关的其他工作,这就是为什么第一个总是需要更多时间的原因。

    在进行基准测试之前。

    1. 确保所有对象都已创建,并且您只测量实际过程所花费的时间。
    2. 还可以尝试在多线程环境中运行它们以获得最佳数量。

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-11-13
      • 1970-01-01
      • 2011-01-14
      • 2015-10-10
      • 2016-04-17
      • 1970-01-01
      • 2017-08-17
      相关资源
      最近更新 更多