alex-heifetz/stopwatch

1.0.0 2024-03-03 09:54 UTC

This package is auto-updated.

Last update: 2024-09-08 12:24:25 UTC


README

GitHub Release GitHub Downloads (all assets, all releases) GitHub License Packagist Dependency Version

为什么你需要这个

如果你不希望使用复杂的工具进行代码分析,但只是需要找到所有代码执行缓慢的地方。

安装与加载

只需将此行添加到你的 composer.json 文件

"alex-heifetz/stopwatch": "^1.0"

或者运行

composer require seraph90/stopwatch

简单示例

<?php

// Import Stopwatch class into the global namespace
use Heifetz\Stopwatch;

// Load Composer's autoloader
require 'vendor/autoload.php';

// Create an instance;
// We can set a threshold that doesn't interest us
$stopwatch = new Stopwatch(210000);

usleep(500000);
// Add first time measurement
$stopwatch->add('500000');

usleep(200000);
// Add another, this one must be skipped by threshold
$stopwatch->add('200000');

usleep(300000);
$stopwatch->add('300000');

// Display all timings 
print_r($stopwatch->getTimings());
// Result like:
//
// Array
// (
//     [500000] => 0.505021
//     [300000] => 0.300916
// )
//