承接 lavoiesl/php-benchmark 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

lavoiesl/php-benchmark

最新稳定版本:v1.4

Composer 安装命令:

composer require lavoiesl/php-benchmark

包简介

Tool to compare different functions in PHP

README 文档

README

Tool to compare different functions in PHP

Install

Via Composer

composer require lavoiesl/php-benchmark

Usage

<?php
$benchmark = new \Lavoiesl\PhpBenchmark\Benchmark();

$benchmark->add('md5',   function() { return md5('test');   });
$benchmark->add('sha1',  function() { return sha1('test');  });

$benchmark->run();
?>

You can run $benchmark->run(false) to get results without any output

Notes about memory usage

Memory usage is monitored using register_tick_function but this does not do a good job at analysing small statements since the memory gets cleaned too quickly.

A simple trick is the return the value, the AbstractTest stores it temporarily.

To ensure proper tick analysis, use declare(ticks = 1); as early as possible.

See the memory test.

Output

Running tests 3000 times.
Testing 2/2 : sha1

Test       Time   Time (%)   Memory   Memory (%)
md5     1304 ms                 0 B
sha1    2077 ms       59 %      0 B

Optimal test count guessing

By default, Benchmark will try to find an optimal number of runs so that each test takes a maximum of 2 seconds.

You can change this by forcing it with $benchmark->setCount($n) or change the time with $benchmark->guessCount($max_seconds).

Writing custom tests

You can extend AbstractTest and provide your own wrapper.

For an example of this, see the command test and the corresponding class.

A full example can be seen here: https://github.com/lavoiesl/php-cache-comparison

统计信息

  • 总下载量: 49.59k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 97
  • 点击次数: 1
  • 依赖项目数: 4
  • 推荐数: 0

GitHub 信息

  • Stars: 96
  • Watchers: 2
  • Forks: 5
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2013-08-12