[Solar-talk] Pager helper changes

Rodrigo Moraes rodrigo.moraes at gmail.com
Sun Jul 1 09:07:11 CDT 2007


2007/7/1, Rodrigo Moraes
> a preg_match_all would be something like
> 5x slower than vsprintf, but is this something to worry about?

I made a benchmark using Solar_Text_Bench, but sometimes the results
are strange :P:

name              : diff : total
__start           : 0.000000 : 0.000000
benchVSprintF     : 0.006196 : 0.006196
benchPregMatchAll : -0.341567 : -0.335371
__stop            : 0.000000 : -0.335371

I don't understand the negative value, but it only happens sometimes.
Here's the comparison class:

class Tipos_Bench_Placeholder extends Solar_Test_Bench
{
    public function benchVSprintF()
    {
        $string = '%1$d-%2$d de %3$d';
        $replace = array(101, 150, 2010);

        return vsprintf($string, (array) $replace);
    }

    public function benchPregMatchAll()
    {
        $string = ':item_x-:item_y of :count';
        $replace = array(
            'item_x' => 101,
            'item_y' => 150,
            'count'  => 2010,
        );

        preg_match_all(
            "/:([a-zA-Z_][a-zA-Z0-9_]*)/m",
            $string . "\n",
            $matches
        );

        return str_replace($matches[0], $replace, $string);
    }
}

-- rodrigo


More information about the Solar-talk mailing list