> > Well, I assumed that the overhead wouldn't be too significant, but I
> > admit I didn't do any measurements whatsoever. Is there any existing
> > good benchmark, or should I just loop a million times through a few
> > random lines of code and measure this?
>
> Yup :)

OK, I did some _very_ simple measurements, and the results aren't too
bad. But is there really no benchmark that you PHP developers use
regularly to test your changes? What I did must surely be very
artificial, not reflecting real-world usage and performance very
much.

I loop 500,000 times through a block of random code that contains:
- assignment of strings and numbers to simple variables
- function call
- array access by numeric index and by string key
- an if condition
- a string concatenation
- some arithmetic operations
- and occasionally an echo statement
- no usage of the new string types

The script runs for about 47.35 seconds (an average from 10
consecutive runs) on unmodified PHP 4.2.0 (default ./configure with
no parameters), and about 48.02 seconds on my modified version.
That's only 1.4% slower. If you want my opinion, I will gladly
sacrifice that. :-)

The results differ with the code in the loop - in the worst case that
I saw the difference was about 4%, in the best case my modified
version was actually a tiny bit quicker :-))) - must be some
alignment magic.

Any ideas on an improvement of the benchmark?

The script:

<?php
    function getmicrotime() {
        list($usec, $sec) = explode(" ",microtime());
        return ((float)$usec + (float)$sec);
    }

    function fun($param) {
        return 2 * $param + 1;
    }

    $time1 = getmicrotime();
    echo "Started in time $time1.\n";
    for ($i = 0; $i < 500000; $i++) {
        $var1 = fun($i);
        $var2 = 123456;
        $var3 = "asd";
        $var4 = array();
        if ($var1 < $var2)
            $var3 .= "yes";
        else
            $var3 .= "no: $var2";
        if ($i % 200 == 0)
            echo "$var3\n";
        $var4[] = $var1;
        $var4['key'] = $var3;
        $var2 = $var4[0] + $var4['key'];
    }
    $time2 = getmicrotime();
    echo "Finished in time $time2.\n";
    echo "Duration: " . ($time2 - $time1) . "\n";
?>

Vaclav Dvorak  ([EMAIL PROTECTED])
http://nebuchadnezzar.zion.cz/

-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to