8000 Speed up StreamSelectLoop · Issue #36 · reactphp/event-loop · GitHub
[go: up one dir, main page]

Skip to content
Speed up StreamSelectLoop #36
Closed
Closed
@greevex

Description

@greevex

There is very simple way to speed up StreamSelectLoop, because usleep(0) not skipping sleep, cuz it function call;

$t = microtime(true);
usleep(0);
$r = microtime(true);
echo ($r-$t)*1000000; //69.856643676758

vs

$t = microtime(true);
0 && usleep(0);
$r = microtime(true);
echo ($r-$t)*1000000; //5.9604644775391

So in the cycle with timeout in variable

$timeout = 0;
$start = microtime(true);
for($i = 0; $i < 100000; $i++) {
    usleep($timeout);
}
echo microtime(true) - $t; //6.6996

vs

$timeout = 0;
$start = microtime(true);
for($i = 0; $i < 100000; $i++) {
    $timeout && usleep($timeout); //skip null and 0 sleeps
}
echo microtime(true) - $t; //0.026

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0