-
Notifications
You must be signed in to change notification settings - Fork 66
Example benchmark #96
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
/vendor/ | ||
/composer.lock | ||
/_storage |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
|
||
/** | ||
* Hoa | ||
* | ||
* | ||
* @license | ||
* | ||
* New BSD License | ||
* | ||
* Copyright © 2007-2016, Hoa community. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* * Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* * Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* * Neither the name of the Hoa nor the names of its contributors may be | ||
* used to endorse or promote products derived from this software without | ||
* specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE | ||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
namespace Hoa\Ruler\Test\Benchmark; | ||
|
||
/** | ||
* @Revs(10) | ||
* @Iterations(10) | ||
* @OutputTimeUnit("milliseconds") | ||
*/ | ||
class RulerBench | ||
{ | ||
private $ruler; | ||
private $context; | ||
|
||
public function setUpAssert() | ||
{ | ||
$this->ruler = new \Hoa\Ruler\Ruler(); | ||
|
||
// 2. Create a context. | ||
$this->context = new \Hoa\Ruler\Context(); | ||
$this->context['group'] = 'customer'; | ||
$this->context['points'] = function () { | ||
return 42; | ||
}; | ||
} | ||
|
||
public function provideRules() | ||
{ | ||
return [ | ||
[ | ||
'rule' => 'group in ["customer", "guest"] and points > 30' | ||
], | ||
[ | ||
'rule' => 'group in ["customer", "guest"]' | ||
], | ||
[ | ||
'rule' => 'points > 30' | ||
], | ||
]; | ||
} | ||
|
||
/** | ||
* Benchmark parsing with rules of different complexity. | ||
* Executes the method once (warmup) before measuring time. | ||
* | ||
* @Warmup(1) | ||
* @BeforeMethods({"setUpAssert"}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you have a default There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can have an abstract class which defines a |
||
* @ParamProviders({"provideRules"}) | ||
*/ | ||
public function case_assert($params) | ||
{ | ||
$this->ruler->assert($params['rule'], $this->context); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we move this file in a single place, like in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The issue would be if you wanted to define f.e. a custom report. However, most, if not all, of the configuration options can be specified at the CLI, so if you wrap it in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could also add a Hoa phpbench extension which programatically adds reports if required. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, sounds interesting. Can you tell me more about it please? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The The extensions can be enabled via. the command line or in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would you like to give it a try? Please, feel free to say no! |
||
"bootstrap": "vendor/autoload.php", | ||
"path": "Test/Benchmark", | ||
"subject_pattern": "^case_.*", | ||
"reports": { | ||
"hoa": { | ||
"extends": "aggregate", | ||
"break": ["benchmark", "subject"], | ||
"cols": [ "params", "revs", "its", "mem_peak", "best", "mean", "mode", "rstdev" ] | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can rename
RulerBench
toRuler
since this is anBenchmark
namespace.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Historically this was a mandatory suffix (like
Test
in PHPUnit), but not since 0.12 so, can do.