Skip to content

Instantly share code, notes, and snippets.

@danemacmillan
Created January 15, 2014 00:41
Show Gist options
  • Select an option

  • Save danemacmillan/8428801 to your computer and use it in GitHub Desktop.

Select an option

Save danemacmillan/8428801 to your computer and use it in GitHub Desktop.

Revisions

  1. danemacmillan created this gist Jan 15, 2014.
    36 changes: 36 additions & 0 deletions gistfile1.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    <?php

    $iterations = 10000;
    $str = 'The speed of calculating the length of this string will be performed.';

    function a($s)
    {
    $l = strlen($s);
    }

    function b($s)
    {
    $l = mb_strlen($s);
    }


    $a_time = 0;
    $i = 0;
    $a_start = microtime(true);
    while ($i <= $iterations) {
    a($str);
    $i++;
    }
    $a_end = microtime(true);

    $b_time = 0;
    $i = 0;
    $b_start = microtime(true);
    while ($i <= $iterations) {
    b($str);
    $i++;
    }
    $b_end = microtime(true);

    echo 'strlen: ' . ($a_end - $a_start) . '<br />';
    echo 'mb_strlen: ' . ($b_end - $b_start);