测试任何平台的测试速度

1.0.0 2020-10-26 09:32 UTC

This package is auto-updated.

Last update: 2024-09-26 18:15:22 UTC


README

这是一个用于轻松性能测试某些功能的实用工具。

安装

composer require iiispikeriii/speedy

使用

$speedy = new Speedy();
print $speedy->runTestByName(TestList::PHP_ARR_SORT);

或者

print Speedy::test(TestList::PHP_INC_PREF_POST);

如果您只想获取速度测试结果 - 使用 onlyData 参数,其值为 true

print Speedy::test(TestList::PHP_INC_PREF_POST, [], true);

或者

$params = [ 
    'name' => 'Speedy ++i vs i++',  
    'volumesTest' => [100, 1000, 2000, 3000], 
    'repeatTest' => 5, 
    'viewers' => [ViewerList::VIEWER_TGROUP, ViewerList::VIEWER_TAVG, ViewerList::VIEWER_GBUBLE], 
    'tester' => 'tester' => TesterList::TESTER_PHP
];  
print Speedy::test(TestList::PHP_INC_PREF_POST, $params);

查看者

  • ViewerList::VIEWER_TLIST - 表格列表结果
  • ViewerList::VIEWER_TGROUP - 表格分组结果
  • ViewerList::VIEWER_TAVG - 表格平均结果
  • ViewerList::VIEWER_GBUBLE - 气泡图结果

测试

  • TestList::PHP_INC_PREF_POST - 预先增量后增量 (++i 和 i++) 的比较
  • TestList::PHP_ARR_READ - 与 "while" "for" "foreach" 读取数组的比较
  • TestList::PHP_ARR_SORT - 与堆、气泡、选择、插入和快速排序数组的比较
  • TestList::PHP_SOF_VS_COUNT - sizeof() 与 count() 的比较

测试者

  • TesterList::TESTER_PHP - 使用 PHP 函数 microtime 和 memory_get_usage 进行测试
  • TesterList::TESTER_XHPROF - 使用 XHProf 扩展进行测试,需要 XHProf。
    • xhprof_lib - xhprof_lib.php 的路径(非必需)
    • xhprof_runs - xhprof_runs.php 的路径(非必需)

比较自定义函数

$myFunc1 =  function($size) 
{
    ... custom code ... 
};  
    
$myFunc2 = function($size)  
{
    ... custom code ... 
};  

每个自定义函数都应该接受 int 参数 - 从 volumesTest 的工作负载

print Speedy::compare(['nameFunc1' => $myFunc1, 'nameFunc2' => $myFunc2]);  

或者

$params = [ 
    'name' => 'Compare functions',   
    'volumesTest' => [100, 1000, 2000, 3000], 
    'repeatTest' => 5, 
    'viewers' => [ViewerList::VIEWER_TLIST, ViewerList::VIEWER_TGROUP, ViewerList::VIEWER_TAVG, ViewerList::VIEWER_GBUBLE], 
    'tester' => TesterList::TESTER_XHPROF,
];  
print Speedy::compare(['nameFunc1' => $myFunc1, 'nameFunc2' => $myFunc2], $params);

示例查看者

VIEWER_TLIST

"table data list viewer"

VIEWER_TGROUP

"table data group viewer"

VIEWER_TAVG

"table data group viewer"

VIEWER_GBUBLE

"graph data buble viewer"