Last active
August 31, 2017 08:07
-
-
Save nanasess/ad0f6ce667df6ef77e8537f7d9ecbfca to your computer and use it in GitHub Desktop.
Benchmark of TranslationLoader
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 __DIR__.'/vendor/autoload.php'; | |
$r = new \ReflectionClass('\Symfony\Component\Validator\Validation'); | |
$xlifffile = dirname($r->getFilename()).'/Resources/translations/validators.en.xlf'; | |
$yamlfile = __DIR__.'/validators.en.yml'; | |
$phpfile = __DIR__.'/validators.en.php'; | |
$Loader = new \Symfony\Component\Translation\Loader\XliffFileLoader(); | |
$catalog = $Loader->load($xlifffile, 'en', 'validators'); | |
$message = $catalog->all('validators'); | |
$yaml = \Symfony\Component\Yaml\Yaml::dump($message); | |
file_put_contents($yamlfile, $yaml); | |
file_put_contents($phpfile, '<?php'.PHP_EOL.'return '.var_export(\Symfony\Component\Yaml\Yaml::parse($yaml), true).';'); | |
$XliffLoader = '\Symfony\Component\Translation\Loader\XliffFileLoader'; | |
$YamlLoader = '\Symfony\Component\Translation\Loader\YamlFileLoader'; | |
$PhpLoader = '\Symfony\Component\Translation\Loader\PhpFileLoader'; | |
$loaders = [$XliffLoader => $xlifffile, $YamlLoader => $yamlfile, $PhpLoader => $phpfile]; | |
foreach ($loaders as $loader_class => $file) { | |
echo $loader_class.PHP_EOL; | |
$loader = new $loader_class; | |
$start = microtime(true); | |
for ($i = 0; $i < 1000; $i++) | |
$loader->load($file, 'en', 'validators'); | |
$end = microtime(true); | |
echo '=> '.($end - $start).PHP_EOL; | |
} |
Author
nanasess
commented
Aug 31, 2017
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment