<commit_before><?php

const MB = 1048576;
const I = 100000;

function show_memory($message = '')
{
    echo '------------------------------------------', PHP_EOL;
    echo $message, PHP_EOL;
    echo '------------------------------------------', PHP_EOL;
    echo 'Current memory usage: ',      memory_get_usage()          / MB, 'MB', PHP_EOL;
    echo 'Peak memory usage: ',         memory_get_peak_usage()     / MB, 'MB', PHP_EOL;
    echo 'Current real memory usage: ', memory_get_usage(true)      / MB, 'MB', PHP_EOL;
    echo 'Peak real memory usage: ',    memory_get_peak_usage(true) / MB, 'MB', PHP_EOL;
}

show_memory('Bare init');

require dirname(__DIR__) . '/vendor/autoload.php';

use React\EventLoop\Factory as EventLoopFactory;
use React\EventLoop\Timer\Timer;
use WyriHaximus\React\ChildProcess\Messenger\Factory as MessengerFactory;
use WyriHaximus\React\ChildProcess\Messenger\Messages\Factory as MessagesFactory;
use WyriHaximus\React\ChildProcess\Messenger\Messenger;

show_memory('Begin');

$loop = EventLoopFactory::create();

MessengerFactory::parentFromClass('WyriHaximus\React\ChildProcess\Messenger\ReturnChild', $loop)->then(function (Messenger $messenger) use ($loop) {
    $messenger->on('error', function ($e) {
        echo 'Error: ', var_export($e, true), PHP_EOL;
    });

    $i = 0;
    $loop->addPeriodicTimer(0.0001, function (Timer $timer) use (&$i, $messenger, $loop) {
        if ($i >= I) {
            $timer->cancel();
            $messenger->softTerminate();

            show_memory('Completed messaging');

            $loop->addTimer(5, function () {});
            return;
        }

        $messenger->rpc(MessagesFactory::rpc('return', [
            'i' => $i,
            'time' => time(),
        ]));

        $i++;
    });<commit_msg>Benchmark style fix<commit_after><?php

const MB = 1048576;
const I = 100000;

function show_memory($message = '')
{
    echo '------------------------------------------', PHP_EOL;
    echo $message, PHP_EOL;
    echo '------------------------------------------', PHP_EOL;
    echo 'Current memory usage: ',      memory_get_usage()          / MB, 'MB', PHP_EOL;
    echo 'Peak memory usage: ',         memory_get_peak_usage()     / MB, 'MB', PHP_EOL;
    echo 'Current real memory usage: ', memory_get_usage(true)      / MB, 'MB', PHP_EOL;
    echo 'Peak real memory usage: ',    memory_get_peak_usage(true) / MB, 'MB', PHP_EOL;
}

show_memory('Bare init');

require dirname(__DIR__) . '/vendor/autoload.php';

use React\EventLoop\Factory as EventLoopFactory;
use React\EventLoop\Timer\Timer;
use WyriHaximus\React\ChildProcess\Messenger\Factory as MessengerFactory;
use WyriHaximus\React\ChildProcess\Messenger\Messages\Factory as MessagesFactory;
use WyriHaximus\React\ChildProcess\Messenger\Messenger;

show_memory('Begin');

$loop = EventLoopFactory::create();

MessengerFactory::parentFromClass('WyriHaximus\React\ChildProcess\Messenger\ReturnChild', $loop)->then(function (Messenger $messenger) use ($loop) {
    $messenger->on('error', function ($e) {
        echo 'Error: ', var_export($e, true), PHP_EOL;
    });

    $i = 0;
    $loop->addPeriodicTimer(0.0001, function (Timer $timer) use (&$i, $messenger, $loop) {
        if ($i >= I) {
            $timer->cancel();
            $messenger->softTerminate();

            show_memory('Completed messaging');

            $loop->addTimer(5, function () {
            });

            return;
        }

        $messenger->rpc(MessagesFactory::rpc('return', [
            'i' => $i,
            'time' => time(),
        ]));

        $i++;
    });
{'fraction_non_alphanumeric': 0.19299221357063404, 'fraction_numerical': 0.011123470522803115, 'mean_word_length': 2.5649157581764124, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6918347', 'n_tokens_mistral': 1192, 'n_tokens_neox': 1118, 'n_words': 230}