webops/runtime

用于数学计算的包

dev-master 2019-08-28 22:32 UTC

This package is auto-updated.

Last update: 2024-09-29 06:14:19 UTC


README

版本 0.1

运行时

运行时类是为了基准测试而制作的。您可以修改它或根据需要在所有项目(商业或非商业)中使用它。您可以将它包裹在函数或方法周围,或传递对象或className及其方法和参数,并检查它们的运行时间。

此类使用bcmath php扩展,因此您必须安装它。您可以通过在扩展部分中运行phpinfo()来检查此设置。此外,您需要在php.ini中将bcmath.scale设置为13或更多,因为我们以0.0000000000001的精度显示浮点数。

如何使用它?

使用composer安装它

将其添加到composer.json中

{
    "minimum-stability": "dev",
    "prefer-stable" : true,
    "require": {
        "webops/runtime": "dev-master"
    }
}

然后执行composer install。

或者,您也可以:composer require webops/runtime,请注意,目前的最低稳定性设置为"dev"。

使用方法

  1. 在函数或方法内部:使用sec()方法

    • 将其包含在您喜欢的位置
    • 使用new Runtime实例化它
    • 使用$instance->setStartTime(microtime(true))设置开始时间
    • $instance->setEndTime(microtime(true))设置结束时间
    • 然后,要获取运行时间,请执行$runtime->sec()
  2. 从对象外部:使用objMethodSec()方法

    • 将其包含在您喜欢的位置
    • 使用new Runtime实例化它
    • 使用$runtime->setObject(new YourObject)设置对象
    • 使用$runtime->setMethod('yourMethodName')设置方法
    • 如果有参数,使用$runtime->setArgs(['array', $of, 'arguments'])设置参数
    • 并最终运行$runtime->objMethodSec()
  3. 类内部的静态方法:使用staticSec()方法

    • 将其包含在您喜欢的位置
    • 使用new Runtime实例化它
    • 使用$runtime->setClass('Fully/Qualified/ClassName')设置类
    • 使用$runtime->setMethod('yourMethodName')设置方法
    • 如果有参数,使用$runtime->setArgs(['array', $of, 'arguments'])设置参数
    • 并最终运行$runtime->staticSec()
  4. 类内部的方法:使用classMethodSec()方法

    • 将其包含在您喜欢的位置
    • 使用new Runtime实例化它
    • 使用$runtime->setClass('Fully/Qualified/ClassName')设置类
    • 使用$runtime->setMethod('yourMethodName')设置方法
    • 如果有参数,使用$runtime->setArgs(['array', $of, 'arguments'])设置参数
    • 并最终运行$runtime->classMethodSec()

这是一个基本版本,将会改进。