ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

rtrim vs. preg_replace vs. ereg_replace

April 21, 2008 1:00am

Subscribe [1]
  • #1 / Apr 21, 2008 1:00am

    BorisK

    45 posts

    I was checking the file_helper.php code today when line 124 struck me as unnecessarily complex way to trim the slash.

    $path = preg_replace("|^(.+?)/*$|", "\\1", $path);

    The same code can be rewriten as:

    $path = rtrim($path,'/');

    In this case rtrim command is four times faster than preg_replace and more readable as well.

    Of course, ereg_replace performs the worst. Here are benchmarking results for 10m iterations:

        rtrim: 0.649 s
    preg_replace: 2.868 s
    ereg_replace: 5.750 s

  • #2 / Apr 21, 2008 2:33am

    BorisK

    45 posts

    Also, in the path_helper.php on line 55, replacing the line that adds a slash to a path

    $path = preg_replace("#([^/])/*$#", "\\1/", $path);

    with

    $path = rtrim($path,'/').'/';

    speeds things up by about 6-7 times.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases