Skip to content

Huge speed boost compared to monolog #9

Description

@8ctopus

Hey Franck,

Did some speed tests comparing Apix vs. Monolog, it turns out in deferred mode, the speed gains are huge.

-----------------------------------
platform           :      WINNT x64
php version        :          8.1.4
xdebug             :             on
memory limit       :           512M
max execution      :              0
time per iteration :           20ms
iterations         :            250
-----------------------------------
---------------------------------------------------------------
0                  : logger_monolog   logger_apix
mean               :             25          1430      +5564.1%
median             :             18          1756      +9934.3%
mode               :              3          2013     +67000.0%
minimum            :              1            28      +2700.0%
maximum            :             73          2183      +2890.4%
quartile 1         :              5           750     +14900.0%
quartile 3         :             51          1979      +3780.4%
IQ range           :             46          1229      +2571.7%
std deviation      :             21           654      +2941.1%
normality          :          30.7%         30.7%
---------------------------------------------------------------

And respective code

$file = new Apix\Log\Logger\File('log_apix.log');
$file
    // intercept logs that are >= `warning`
    ->setMinLevel('warning')
    // don't propagate to further buckets
    ->setCascading(true)
    // postpone/accumulate logs processing
    ->setDeferred(true);

$log = new Apix\Log\Logger([$file]);

$stdout = new Apix\Log\Logger\Stream('php://stdout', 'a');
$stdout
    // intercept logs that are >= `warning`
    ->setMinLevel('warning')
    // don't propagate to further buckets
    ->setCascading(true)
    // postpone/accumulate logs processing
    ->setDeferred(true);

$log->add($stdout);

while (microtime(true) < $time_limit) {
    $log->warning('test');
    ++$iterations;
}
$log = new Monolog\Logger('test');
$log->pushHandler(new Monolog\Handler\StreamHandler('log_monolog.log', Monolog\Level::Warning));

// log to stdout
$log->pushHandler(new Monolog\Handler\StreamHandler('php://stdout', Monolog\Level::Warning));

while (microtime(true) < $time_limit) {
    $log->warning('test');
    ++$iterations;
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions