<?php
function contar($texto){
    $array = array_filter(preg_split('/[\s\.\,]+/s', strtolower($texto)), function($palabra){
        if (in_array($palabra, ['loca', 'idiota', 'viagra'])) return $palabra;
    });
    foreach (array_count_values($array) as $k => $v);
    //No imprimo datos para no generar 1000 líneas de texto
}

function autoSpam($txt){
	$cuenta = 0;
	$txt = explode(" ", $txt);
	 
	$noPermitidas = array('idiota','loca','viagra');
	 
	foreach ($txt as $word){
	    foreach ($noPermitidas as $spam) {
	        if(preg_match("/$spam/i",$word)){
	            $cuenta++;
	        }
	    }
	}
	return $cuenta;
}

$inicio = microtime(true) * 1000;
for ($i = 0; $i < 1000; $i++) contar('la loCa del bosque era muy loca y entonces enloquecio muy LOCA mente. Locura');
$fin = microtime(true) * 1000;
echo 'Tiempo Alexis88: ' . ($fin - $inicio);

echo "\n";

$inicio = microtime(true) * 1000;
for ($i = 0; $i < 1000; $i++) autoSpam('la loCa del bosque era muy loca y entonces enloquecio muy LOCA mente. Locura');
$fin = microtime(true) * 1000;
echo 'Tiempo GeekGirl: ' . ($fin - $inicio);