Zephir performance when used with PHP functions.

I have a couple of general questions (still a newbie in Zephir, not knowing C, and thinking from high-level PHP programmer standpoint). 1. Is this right that Zephir gets much slower (sometimes slower than PHP or not much faster) when it uses PHP functions/classes. (based on https://groups.drupal.org/node/456053 ). How much slower it can be. Or otherwise is it much, much faster when it doesn't use PHP functions/classes? 2. If yes (is slower), is then there a way to use PHP functions in a way to increase performance, f.e. preg_mach, etc. (i think i will never implement on my own some regular expressions in Zephir :) ) 3. Is this tool https://github.com/fezfez/php-to-zephir 100% working/effective? I see ovr user is a contributor - i saw him from time to time on phalcon forums. What about performance after using it. 4. What can be the difference in performance between skillfully optimised Zephir and not optimised Zephir class done by someone inexperienced?

I'am a bit ignorant on the matter so answers to these questions could give me and other (PHP especially) users a better overal picture and comprehend it better.



1.7k

PHP 6, Zephir 12 seconds when echo function PHP 3, Zephir 8 seconds when echo is removed and more variables are made static where it possible PHP 15, Zephir 0.1 of a second when additionally there is no preg_match function (time() is), and no condition if

Can i do anything to change the first results that Zephir performs better?

public function speedTest() {

        $timeone=time();
        for ($a=0;$a<1000;$a++) {
            $b=10*$a-1000;    
            $matchresult = preg_match("/mymailaddress(@)?example.com/sU", "[email protected]");
            if ($matchresult!=0) {
                echo("t:".$matchresult."##".$b);
            } else {
                echo("f:".$matchresult."##".$b);
            }
        }
        $timetwo=time();

    }
    public static function speedTest() {

        var b, timeone, timetwo, matchresult;
        int a;

        let timeone=time();
        for a in range(0, 1000) {
            let b=10*a - 1000;    
            let b=(string) b;
            let matchresult = preg_match("/mymailaddress(@)?example.com/sU", "[email protected]");
            if matchresult!=0 {
                echo("t:".matchresult."#".b);
            } else {
                echo("f:".matchresult."#".b);
            }
        }
        let timetwo=time();

    }


1.7k

Ok. I've search a bit and as i know that the performance can be slower in Zephir for php world functions especially, and it can have something to do with the dynamic nature of variables passed to the functions. With the php time() function only i had an amazing performance - that 0.1 (a function without params) of a second is not an accident and i've forgotten to show loop i used for the tests: Zephir - invoked staticly from php: ```php public static function loopTest() {

    var timeone, timetwo, timeresult; 
    int a;

    let timeone=time();
    for a in range(0, 250) {
        \Zmanager\Phalcon\Db\Adapter\Pdo\Sqliteextended::speedTest();
    }
    let timetwo=time();
    let timeresult=timetwo-timeone;
    let timeresult=(string) timeresult;
    echo("<div style='position: absolute;top: 50px;left; 0;background: #0a0;color: #fff'>###".timeresult."###</div>");
    ob_flush();

 }

of PHP for PHP function ```php

    $timeone=time();
    for ($a=0;$a<250;$a++) {
        $this->speedTest();
    }
    $timetwo=time();
    echo "<div style='position: absolute;top: 0;left; 0;background: #f00;color: #fff'>###".($timetwo-$timeone)."###</div>";ob_flush();
I also used this for zephir:

php $timeone=time(); for ($a=0;$a<100;$a++) { \Zmanager\Phalcon\Db\Adapter\Pdo\Sqliteextended::speedTest(); } $timetwo=time(); echo "<div style='position: absolute;top: 50px;left; 0;background: #0a0;color: #fff'>###".($timetwo-$timeone)."###</div>";ob_flush();

```

And as far as i remember the results are similar (not a jump in performance speed)



1.7k

I found out that optimisers can be used (improving performance among other things):

http://zephir-lang.com/optimizers.html

Still, there already are optimisers for preg_match (time) function pre-defined in Zephir so i am a bit confused about my learning examples' performance:

https://github.com/phalcon/zephir/blob/master/Library/Optimizers/FunctionCall/PregMatchOptimizer.php