<?php


$nr_loops = 1000000; // 1 milhão
$link = '13542345/essa_e_minhastring';

// explode
$before = microtime(true);
for ($i=0 ; $i<$nr_loops ; $i++) {
    $partes = explode("/", $link);
}
echo $partes[0]." | ";
$after = microtime(true);
echo ($after-$before)/$i . " sec / por explode\n";

// preg_match
$before = microtime(true);
for ($i=0 ; $i<$nr_loops ; $i++) {
	$pattern = '/[^\/]+/';
    preg_match($pattern, $link, $partes, PREG_OFFSET_CAPTURE);
}
$after = microtime(true);
echo $partes[0][0]." | ";
echo ($after-$before)/$i . " sec / por preg_match\n";

// strtok
$before = microtime(true);
for ($i=0 ; $i<$nr_loops ; $i++) {
    $parte  = strtok($link, '/');
}
$after = microtime(true);
echo $parte." | ";
echo ($after-$before)/$i . " sec / por strtok\n";

// substr
$before = microtime(true);
for ($i=0 ; $i<$nr_loops ; $i++) {
    $parte = substr($link, 0, strpos($link, "/"));
}
$after = microtime(true);
echo $parte." | ";
echo ($after-$before)/$i . " sec / por substr\n";

