phptrace icon indicating copy to clipboard operation
phptrace copied to clipboard

如何控制for循环下的重复抓取

Open oikomi opened this issue 9 years ago • 1 comments

对于下面的代码, 它会打印 strpos栈 200次,显然对性能影响极大,有没有办法控制打印的次数呢

function test() {
        for ($idx = 0; $idx < 200; $idx++) {
                strpos("You love php, I love php too!","php");
        }
}

oikomi avatar Dec 21 '15 06:12 oikomi

Strictly speaking, this code snippet do affect performance.

for some simple code, perhaps phptrace can do some merging operation to reduce the output size like this

> strpos("You love php, I love php too!", "php") called at [try.php:5] x 200
< strpos("You love php, I love php too!", "php") = 9 called at [try.php:5] x 200

But, we can not explicitly say what the simple is.

Such this, I just add a variable in string.

function test() {
    for ($idx = 0; $idx < 200; $idx++) {
        strpos("You love php, I love php too! $idx","php"); // notice this $idx
    }
}

It makes the problem more difficult.

Luckily, phptrace still can support for this by doing some runtime-analyzing, and merging similar operations, but it's too complex to implement. (Sounds like JIT)

So I'm curious what you want to trace? could you send a full example?

monque avatar Mar 14 '16 07:03 monque