Created
March 11, 2014 14:02
-
-
Save webmozart/9486236 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once __DIR__.'/vendor/autoload.php'; | |
use Symfony\Component\Validator\Validation; | |
use Symfony\Component\Validator\Constraints\Length; | |
use Symfony\Component\Validator\Constraints\NotNull; | |
use Symfony\Component\Validator\Constraints\Range; | |
$validator = Validation::createValidatorBuilder() | |
->setApiVersion(Validation::API_VERSION_2_4) | |
// ->setApiVersion(Validation::API_VERSION_2_5) | |
// ->setApiVersion(Validation::API_VERSION_2_4 | Validation::API_VERSION_2_5) | |
->enableAnnotationMapping() | |
->getValidator(); | |
class BenchClass | |
{ | |
/** | |
* @NotNull | |
* @Range(min=2, max=50) | |
*/ | |
public $foo; | |
/** | |
* @NotNull | |
* @Length(min=3) | |
*/ | |
public $bar; | |
} | |
$object = new BenchClass(); | |
$object->foo = 60; | |
$object->bar = 'fo'; | |
$constraint = new Range(array('min' => 50)); | |
// Validate once to autoload all needed classes | |
$validator->validate($object); | |
$time = microtime(true); | |
for ($i = 0; $i < 20; ++$i) { | |
$validator->validate($object); | |
} | |
echo 1000*(microtime(true)-$time)."ms\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment