Page MenuHomePhabricator
Paste P17048

preg_match timing loop
ActivePublic

Authored by dancy on Aug 19 2021, 3:11 PM.
Tags
None
Referenced Files
F34606345: preg_match timing loop
Aug 19 2021, 3:11 PM
Subscribers
<?php
$start = microtime(true);
$loops = 1000 * 1000;
for ($i = 0; $i<$loops; $i++) {
$etcdHost = "_etcd._tcp.eqiad.wmnet";
$protocol = 'https';
if ( preg_match( ',^(https?)://(.*)$,', $etcdHost, $matches ) ) {
$protocol = $matches[1];
$etcdHost = $matches[2];
}
}
$elapsed = microtime(true) - $start;
$per_loop = $elapsed / $loops;
$us_per_loop = $per_loop * 1000 * 1000;
$ns_per_loop = $per_loop * 1000 * 1000 * 1000;
echo("Elapsed seconds: $elapsed\n");
echo("Seconds per loop: $per_loop\n");
echo("us per loop: $us_per_loop\n");
echo("ns per loop: $ns_per_loop\n");