mre/phpench 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

mre/phpench

Composer 安装命令:

composer require mre/phpench

包简介

A graphical PHP benchmarking tool

README 文档

README

A pretty graph

PHPench creates a graphical output for a PHP benchmark. Plot the runtime of any function in realtime with GnuPlot and create an image out of the result.

Build Status

Why is it useful?

Algorithms are beautiful

Sometimes the difference between two algorithms is hard to explain but easy to show.
For instance, take two sorting algorithms which both have a best-case runtime of O(n*log n). Depending on the input, one can be much faster than the other. This tools helps you see what's going on.

Death to premature-optimizations

Whenever people tell you that using single quotes instead of double quotes around strings is a performance improvement, it's time to debunk some myths. Most of the time such programmer folklore turns out to be misguided and can actually be pretty harmful.
"Premature emphasis on efficiency is a big mistake which may well be the source of most programming complexity and grief." (Donald Knuth)
Let's be professionals. Let's measure.

Example

Using PHPench feels a bit like writing a visual unit test. Check it out:

<?php

require_once __DIR__.'/../vendor/autoload.php';

/*
 * You can use an closure or a class that implements TestInterface.
 *
 * Data that will be processed by the tested function can be executed
 * without including its execution time. This will provide more accurate data.
 */

abstract class AbstractBenchmark implements \mre\PHPench\BenchmarkInterface
{
    protected $test;

    function setUp($arrSize)
    {
        $this->test = array();
        for ($i=1; $i<$arrSize; $i++) {
            $this->test[$i]= $arrSize % $i;
        }

        return $this->test;
    }
}

class BenchmarkArrayFlip extends AbstractBenchmark
{
    public function execute() {
        $test = array_flip(array_flip($this->test));
    }
}

class BenchmarkArrayUnique extends AbstractBenchmark
{
    public function execute() {
        $test = array_unique($this->test);
    }
}

// Create a new benchmark instance
$phpench = new \mre\PHPench(new \mre\PHPench\Aggregator\MedianAggregator);

// Use GnuPlot for output
$oOutput = new \mre\PHPench\Output\GnuPlotOutput('test2.png', 1024, 768);

// Alternatively, print the values to the terminal
//$oOutput = new \mre\PHPench\Output\CliOutput();

$oOutput->setTitle('Compare array_flip and array_unique');
$phpench->setOutput($oOutput);

// Add your test to the instance
$phpench->addBenchmark(new BenchmarkArrayFlip, 'array_flip');
$phpench->addBenchmark(new BenchmarkArrayUnique, 'array_unique');

// Run the benchmark and plot the results in realtime.
// With the second parameter you can specify
// the start, end and step for each call
$phpench->setInput(range(1,pow(2,16), 1024));
$phpench->setRepetitions(4);
$phpench->run();

Installation

1.) Add this package to your composer.json

{
    "require": {
      "mre/phpench": "*@dev"
    }
}

2.) Install gnuplot (Version 4.6)

For Mac OS X you can install gnuplot via homebrew. For live generated charts you also need to install XQuartz.

Without X11 support:
$ brew install homebrew/versions/gnuplot4

With X11 supprt (recommended!):
$ brew install homebrew/versions/gnuplot4 --with-x11

For Linux use your package manager.

apt-get install gnuplot

3.) Look at the examples for usage

Maintainers

Matthias Endler (@matthiasendler)
Markus Poerschke (@markuspoerschke)

License

Apache License Version 2.0

mre/phpench 适用场景与选型建议

mre/phpench 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 27 次下载、GitHub Stars 达 54, 最近一次更新时间为 2014 年 10 月 30 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「graph」 「stats」 「gnuplot」 「plot」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 mre/phpench 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 mre/phpench 我们能提供哪些服务?
定制开发 / 二次开发

基于 mre/phpench 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 27
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 54
  • 点击次数: 24
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 54
  • Watchers: 6
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-10-30