Unverified Commit a36fe086 authored by Arkadiusz Kondas's avatar Arkadiusz Kondas Committed by GitHub

Add performance test for LeastSquares (#263)

* Install phpbench 🚀

* Add first benchmark for LeastSquares

* Update README and CONTRIBUTING guide

* Fix typo
parent af2d7321
/vendor/ /vendor/
.php_cs.cache .php_cs.cache
/build /build
/tests/Performance/Data/*.csv
...@@ -8,7 +8,7 @@ code base clean, unified and future proof. ...@@ -8,7 +8,7 @@ code base clean, unified and future proof.
You should only open pull requests against the `master` branch. You should only open pull requests against the `master` branch.
## Unit-Tests ## Unit Tests
Please try to add a test for your pull-request. You can run the unit-tests by calling: Please try to add a test for your pull-request. You can run the unit-tests by calling:
...@@ -16,6 +16,22 @@ Please try to add a test for your pull-request. You can run the unit-tests by ca ...@@ -16,6 +16,22 @@ Please try to add a test for your pull-request. You can run the unit-tests by ca
vendor/bin/phpunit vendor/bin/phpunit
``` ```
## Performance Tests
Before first run bootstrap script will download all necessary datasets from public repository `php-ai/php-ml-datasets`.
Time performance tests:
```bash
vendor/bin/phpbench run --report=time
```
Memory performance tests:
```bash
vendor/bin/phpbench run --report=memory
```
## Travis ## Travis
GitHub automatically run your pull request through Travis CI. GitHub automatically run your pull request through Travis CI.
...@@ -23,21 +39,21 @@ If you break the tests, I cannot merge your code, so please make sure that your ...@@ -23,21 +39,21 @@ If you break the tests, I cannot merge your code, so please make sure that your
## Merge ## Merge
Please allow me time to review your pull requests. I will give my best to review everything as fast as possible, but cannot always live up to my own expectations. Please give me time to review your pull requests. I will give my best to review everything as fast as possible, but cannot always live up to my own expectations.
## Coding Standards & Static Analysis ## Coding Standards & Static Analysis
When contributing code to PHP-ML, you must follow its coding standards. To do that, just run: When contributing code to PHP-ML, you must follow its coding standards. To do that, just run:
```bash ```bash
vendor/bin/ecs check src tests --fix composer fix-cs
``` ```
[More about EasyCodingStandard](https://github.com/Symplify/EasyCodingStandard) [More about EasyCodingStandard](https://github.com/Symplify/EasyCodingStandard)
Code has to also pass static analysis by [PHPStan](https://github.com/phpstan/phpstan): Code has to also pass static analysis by [PHPStan](https://github.com/phpstan/phpstan):
```bash ```bash
vendor/bin/phpstan.phar analyse src tests --level max --configuration phpstan.neon composer phpstan
``` ```
......
...@@ -9,11 +9,9 @@ ...@@ -9,11 +9,9 @@
[![Coverage Status](https://coveralls.io/repos/github/php-ai/php-ml/badge.svg?branch=master)](https://coveralls.io/github/php-ai/php-ml?branch=master) [![Coverage Status](https://coveralls.io/repos/github/php-ai/php-ml/badge.svg?branch=master)](https://coveralls.io/github/php-ai/php-ml?branch=master)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/php-ai/php-ml/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/php-ai/php-ml/?branch=master) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/php-ai/php-ml/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/php-ai/php-ml/?branch=master)
<a href="http://www.yegor256.com/2016/10/23/award-2017.html"> <p align="center">
<img src="http://www.yegor256.com/images/award/2017/winner-itcraftsmanpl.png" <img src="https://github.com/php-ai/php-ml/blob/master/docs/assets/php-ml-logo.png" />
style="width:203px;height:45px;"/></a> </p>
![PHP-ML - Machine Learning library for PHP](docs/assets/php-ml-logo.png)
Fresh approach to Machine Learning in PHP. Algorithms, Cross Validation, Neural Network, Preprocessing, Feature Extraction and much more in one library. Fresh approach to Machine Learning in PHP. Algorithms, Cross Validation, Neural Network, Preprocessing, Feature Extraction and much more in one library.
...@@ -35,6 +33,11 @@ echo $classifier->predict([3, 2]); ...@@ -35,6 +33,11 @@ echo $classifier->predict([3, 2]);
// return 'b' // return 'b'
``` ```
## Awards
<a href="http://www.yegor256.com/2016/10/23/award-2017.html">
<img src="http://www.yegor256.com/images/award/2017/winner-itcraftsmanpl.png" width="400"/></a>
## Documentation ## Documentation
To find out how to use PHP-ML follow [Documentation](http://php-ml.readthedocs.org/). To find out how to use PHP-ML follow [Documentation](http://php-ml.readthedocs.org/).
...@@ -51,6 +54,10 @@ composer require php-ai/php-ml ...@@ -51,6 +54,10 @@ composer require php-ai/php-ml
Example scripts are available in a separate repository [php-ai/php-ml-examples](https://github.com/php-ai/php-ml-examples). Example scripts are available in a separate repository [php-ai/php-ml-examples](https://github.com/php-ai/php-ml-examples).
## Datasets
Public datasets are available in a separate repository [php-ai/php-ml-datasets](https://github.com/php-ai/php-ml-datasets).
## Features ## Features
* Association rule learning * Association rule learning
...@@ -120,6 +127,7 @@ Example scripts are available in a separate repository [php-ai/php-ml-examples]( ...@@ -120,6 +127,7 @@ Example scripts are available in a separate repository [php-ai/php-ml-examples](
## Contribute ## Contribute
- [Guide: CONTRIBUTING.md](https://github.com/php-ai/php-ml/blob/master/CONTRIBUTING.md)
- [Issue Tracker: github.com/php-ai/php-ml](https://github.com/php-ai/php-ml/issues) - [Issue Tracker: github.com/php-ai/php-ml](https://github.com/php-ai/php-ml/issues)
- [Source Code: github.com/php-ai/php-ml](https://github.com/php-ai/php-ml) - [Source Code: github.com/php-ai/php-ml](https://github.com/php-ai/php-ml)
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
"php": "^7.1" "php": "^7.1"
}, },
"require-dev": { "require-dev": {
"phpbench/phpbench": "^0.14.0",
"phpstan/phpstan-phpunit": "^0.9.4", "phpstan/phpstan-phpunit": "^0.9.4",
"phpstan/phpstan-shim": "^0.9", "phpstan/phpstan-shim": "^0.9",
"phpstan/phpstan-strict-rules": "^0.9.0", "phpstan/phpstan-strict-rules": "^0.9.0",
......
This diff is collapsed.
...@@ -9,11 +9,9 @@ ...@@ -9,11 +9,9 @@
[![Coverage Status](https://coveralls.io/repos/github/php-ai/php-ml/badge.svg?branch=master)](https://coveralls.io/github/php-ai/php-ml?branch=master) [![Coverage Status](https://coveralls.io/repos/github/php-ai/php-ml/badge.svg?branch=master)](https://coveralls.io/github/php-ai/php-ml?branch=master)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/php-ai/php-ml/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/php-ai/php-ml/?branch=master) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/php-ai/php-ml/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/php-ai/php-ml/?branch=master)
<a href="http://www.yegor256.com/2016/10/23/award-2017.html"> <p align="center">
<img src="http://www.yegor256.com/images/award/2017/winner-itcraftsmanpl.png" <img src="https://github.com/php-ai/php-ml/blob/master/docs/assets/php-ml-logo.png" />
style="width:203px;height:45px;"/></a> </p>
![PHP-ML - Machine Learning library for PHP](assets/php-ml-logo.png)
Fresh approach to Machine Learning in PHP. Algorithms, Cross Validation, Neural Network, Preprocessing, Feature Extraction and much more in one library. Fresh approach to Machine Learning in PHP. Algorithms, Cross Validation, Neural Network, Preprocessing, Feature Extraction and much more in one library.
...@@ -35,6 +33,11 @@ $classifier->predict([3, 2]); ...@@ -35,6 +33,11 @@ $classifier->predict([3, 2]);
// return 'b' // return 'b'
``` ```
## Awards
<a href="http://www.yegor256.com/2016/10/23/award-2017.html">
<img src="http://www.yegor256.com/images/award/2017/winner-itcraftsmanpl.png" width="400"/></a>
## Documentation ## Documentation
To find out how to use PHP-ML follow [Documentation](http://php-ml.readthedocs.org/). To find out how to use PHP-ML follow [Documentation](http://php-ml.readthedocs.org/).
...@@ -105,6 +108,7 @@ Example scripts are available in a separate repository [php-ai/php-ml-examples]( ...@@ -105,6 +108,7 @@ Example scripts are available in a separate repository [php-ai/php-ml-examples](
## Contribute ## Contribute
- Guide: [CONTRIBUTING.md](https://github.com/php-ai/php-ml/blob/master/CONTRIBUTING.md)
- Issue Tracker: [github.com/php-ai/php-ml/issues](https://github.com/php-ai/php-ml/issues) - Issue Tracker: [github.com/php-ai/php-ml/issues](https://github.com/php-ai/php-ml/issues)
- Source Code: [github.com/php-ai/php-ml](https://github.com/php-ai/php-ml) - Source Code: [github.com/php-ai/php-ml](https://github.com/php-ai/php-ml)
......
{
"bootstrap": "tests/Performance/bootstrap.php",
"path": "tests/Performance",
"reports": {
"time": {
"extends": "aggregate",
"title": "The Consumation of Time",
"cols": [ "subject", "mode", "mean", "rstdev", "diff"]
},
"memory": {
"extends": "aggregate",
"title": "The Memory Usage",
"cols": [ "subject", "mem_real", "mem_final", "mem_peak", "diff"],
"diff_col": "mem_peak"
}
}
}
\ No newline at end of file
<?php
declare(strict_types=1);
namespace Phpml\Tests\Performance\Regression;
use PhpBench\Benchmark\Metadata\Annotations\BeforeMethods;
use PhpBench\Benchmark\Metadata\Annotations\Iterations;
use PhpBench\Benchmark\Metadata\Annotations\OutputTimeUnit;
use PhpBench\Benchmark\Metadata\Annotations\Revs;
use Phpml\Dataset\CsvDataset;
use Phpml\Dataset\Dataset;
use Phpml\Regression\LeastSquares;
/**
* @BeforeMethods({"init"})
* @OutputTimeUnit("seconds")
*/
final class LeastSquaresBench
{
/**
* @var Dataset
*/
private $dataset;
public function init(): void
{
$this->dataset = new CsvDataset(__DIR__.'/../Data/bike-sharing-hour.csv', 14);
}
/**
* @Revs(1)
* @Iterations(5)
*/
public function benchLeastSquaresTrain(): void
{
$leastSqueares = new LeastSquares();
$leastSqueares->train($this->dataset->getSamples(), $this->dataset->getTargets());
}
}
<?php
declare(strict_types=1);
require __DIR__.'/../../vendor/autoload.php';
$dataDir = __DIR__.'/Data';
$datasets = [
'https://github.com/php-ai/php-ml-datasets/raw/0.1.0/datasets/bike-sharing-hour.csv',
];
foreach ($datasets as $dataset) {
$path = $dataDir.'/'.basename($dataset);
if (!file_exists($path)) {
if (!copy($dataset, $path)) {
die(sprintf('Failed to download %s', $dataset));
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment