Skip to content

Instantly share code, notes, and snippets.

@relaxnow
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save relaxnow/54229d556b63199c7655 to your computer and use it in GitHub Desktop.
Save relaxnow/54229d556b63199c7655 to your computer and use it in GitHub Desktop.
XPath v.s. JSON on edugain metadata
/opt/local/bin/php53-bin/php /tmp/json_decode.php
count: 1090
peak memory usage: 6 MiB
time: 13.12ms
<?php
$start = microtime(true);
$data = json_decode(file_get_contents("/var/cache/openconext/stoker/edugain/metadata.index.json"));
$idps = array();
foreach ($data->entities as $entityId => $entity) {
if (in_array('idp', $entity->types)) {
$idps[] = $entity;
}
}
echo "count: " . count($idps) . PHP_EOL;
echo "peak memory usage: ". round(memory_get_peak_usage(true)/1024/1024, 2) . " MiB" . PHP_EOL;
echo "time: " . round((microtime(true) - $start) * 1000, 2) . "ms" . PHP_EOL;
/opt/local/bin/php53-bin/php /tmp/xpath.php
count: 1090
peak memory usage: 1.25 MiB
time: 263.38ms
<?php
$start = microtime(true);
$doc = new DomDocument();
$doc->load("/var/cache/openconext/stoker/edugain/saml2-metadata.xml");
$xpath = new DOMXpath($doc);
echo "count: " . $xpath->query("//*[local-name()='IDPSSODescriptor']/..")->length . PHP_EOL;
echo "peak memory usage: " . round(memory_get_peak_usage(true)/1024/1024, 2) . " MiB" . PHP_EOL;
echo "time: " . round((microtime(true) - $start) * 1000, 2) . "ms" . PHP_EOL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment