Created
September 15, 2013 01:40
-
-
Save quicksketch/6567356 to your computer and use it in GitHub Desktop.
Comparing spyc vs. Symfony vs. JSON parsing
This file contains 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__ . '/core/vendor/autoload.php'; | |
require_once __DIR__ . '/core/includes/bootstrap.inc'; | |
drupal_bootstrap(DRUPAL_BOOTSTRAP_CODE); | |
$yaml_files = file_scan_directory('./test_yaml', '/\.yml$/'); | |
$start = microtime(TRUE); | |
$yaml_contents = array(); | |
$parser = new Symfony\Component\Yaml\Parser(); | |
foreach ($yaml_files as $file) { | |
$parser->parse(file_get_contents($file->uri)); | |
// Convert YAML to identical JSON copies of the same files. | |
//$json_version = json_encode($yaml_contents[$file->name]); | |
//$file_name = str_replace('.yml', '.json', str_replace('_yaml', '_json', $file->uri)); | |
//file_put_contents($file_name, json_encode($yaml_contents[$file->name], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)); | |
} | |
$total = microtime(TRUE) - $start; | |
print "Symfony YAML parsing time: $total<br />"; | |
$start = microtime(TRUE); | |
$yaml_contents = array(); | |
require_once __DIR__ . '/spyc/Spyc.php'; | |
foreach ($yaml_files as $file) { | |
spyc_load_file($file->uri); | |
// Convert YAML to identical JSON copies of the same files. | |
//$json_version = json_encode($yaml_contents[$file->name]); | |
//$file_name = str_replace('.yml', '.json', str_replace('_yaml', '_json', $file->uri)); | |
//file_put_contents($file_name, json_encode($yaml_contents[$file->name], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)); | |
} | |
$total = microtime(TRUE) - $start; | |
print "Spyc YAML parsing time: $total<br />"; | |
$json_files = file_scan_directory('./test_json', '/\.json$/'); | |
$start = microtime(TRUE); | |
$json_contents = array(); | |
foreach ($json_files as $file) { | |
json_decode(file_get_contents($file->uri)); | |
} | |
$total = microtime(TRUE) - $start; | |
print "JSON parsing time: $total<br />"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Did you ever post the results of this test anywhere? I'm evaluating which to use.