nice/bench 问题修复 & 功能扩展

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

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

nice/bench

最新稳定版本:1.0.1

Composer 安装命令:

composer require nice/bench

包简介

A simple PHP benchmarking framework

README 文档

README

Build Status

A simple PHP benchmark, useful for the every day micro-optimizer.

<?php

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

use Nice\Benchmark\Benchmark;

$benchmark = new Benchmark(100000, 'String matching');
$benchmark->register('preg_match', function() {
        assert(preg_match('/^test/', 'testing'));
    });

$benchmark->register('strpos', function() {
        assert(strpos('testing', 'test') === 0);
    });

$benchmark->execute();
Running "String matching" consisting of 2 tests, 100,000 iterations...
Values that fall outside of 3 standard deviations of the mean are discarded.

For preg_match out of 98,997 runs, average time was 0.0000118057 seconds.
For strpos out of 99,871 runs, average time was 0.0000104146 seconds.

Results:
Test Name                          	Time                	+ Interval          	Change
strpos                             	0.0000104146        	+0.0000000000       	baseline
preg_match                         	0.0000118057        	+0.0000013912       	13% slower

Installation

The recommended way to install Nice Bench is through Composer. Just run the php composer.phar require command in your project directory to install it:

php composer.phar require nice/bench:~1.0

Usage

Create a file called tests.php in your project directory, and add:

<?php

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

use Nice\Benchmark\Benchmark;

$arr = range(1, 10000);

$benchmark = new Benchmark(10000, 'foreach');
$benchmark->register('foreach with value', function() use ($arr) {
        foreach ($arr as $value) {
        
        }
    });

$benchmark->register('foreach with key, value', function() use ($arr) {
        foreach ($arr as $key => $value) {
            
        }
    });

$benchmark->execute();

Then run tests.php in your terminal:

$ php tests.php
Running "foreach" consisting of 2 tests, 10,000 iterations...
Values that fall outside of 3 standard deviations of the mean are discarded.

For foreach with value out of 9,871 runs, average time was 0.0011523914 seconds.
For foreach with key, value out of 9,874 runs, average time was 0.0016814657 seconds.


Results:
Test Name                          	Time                	+ Interval          	Change
foreach with value                 	0.0011523914        	+0.0000000000       	baseline
foreach with key, value            	0.0016814657        	+0.0005290744       	46% slower

For another example, check out example.php.

统计信息

  • 总下载量: 336
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 13
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 13
  • Watchers: 2
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-11-23

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固