@ 2018-03-11T08:25:39Z <?php
$entity = makeEntity(null,
'SuperWidget', [
'foo' => 'bar',
'baz' => 'bla',
],
// false // Toggle these two line's comments.
true // Leave off or false to not show logging.
);
$entity->send(_m('propBoo', 'hoo'));
$entity->send(_m('propOop', 'Php'));
$entity->send(_m('propBaz', 'Apt'));
$entity->send(_m('withProps', [
['propBaz', 'Oth'],
['propOth', 'Win'],
]));
$entity->send(_m('propGen', ['Era','Tor',]));
// Erases the history, should we have it?
$entity->send(_m('fromProps', [['propOof','Uhh']]));
$props = $entity->send(_i());
foreach($props as $prop => $props) {
echo sprintf('%s(%s=%s)%s',
$entity->key(),
$prop,
\json_encode($props),
PHP_EOL
);
}
function makeEntity(
?int $id = null,
string $type,
?array $props = null,
?bool $log = null
) {
$id = $id ?? random_int(1, 500000);
$logger = _f(!$log ?: function($signal, $message = null, ?string $tmpl = null) use($id) {
$tmpl = sprintf('Receiver(%d, Signal: %s)', $id, $tmpl ?? '[%s](%s)');
echo sprintf($tmpl, $signal, \json_encode($message)).PHP_EOL;
});
$apply = function($changes, $for) use($logger) {
foreach($changes as $set) {
$action = array_shift($set); // First one is the method, PropertySet
list($prop, $value) = $set;
if (substr($prop, 0, 7) !== 'Stream:') $for[$prop] = $value;
$logger(sprintf('Apply(%s=%s)', $action, \json_encode($set)), null, '%s');
}
return $for;
};
$propDecorator = function(array $changes, array $changeSet = []) {
return array_reduce($changes, function($changeSet, array $change) {
$propName = strtolower(substr($change[0], 4));
$changeSet[] = ['PropertySet', $propName, $change];
return $changeSet;
}, $changeSet);
};
$filterSignalOut = function($changeSet) {
return array_filter($changeSet, function($change) {
return substr($change[1], 0, 7) !== 'Stream:';
});
};
$filterSignalIn = function($changeSet) {
return array_filter($changeSet, function($change) {
return substr($change[1], 0, 7) === 'Stream:';
});
};
$changeSet = [
['SIGINI', 'Stream:Init', microtime(),],
['SIGIID', 'Stream:InitId', $id],
['SIGBND', 'Stream:BindProps', $props,], // Initial state.
];
while (true) {
list($signal, $message) = yield;
$signal = preg_replace('/[^a-z\d]/i', '', (string) $signal);
$logger($signal, $message);
if (substr($signal, 0, 4) === 'prop') {
$propName = strtolower(substr($signal, 4));
$changeSet[] = ['PropertySet', $propName, $message];
}
if ($signal === 'withProps') {
$changeSet = $propDecorator($message, $changeSet);
}
if ($signal === 'fromProps') {
$changeSet[] = ['SIGFRM', 'Stream:From', microtime(),];
$changeSet[] = ['SIGIFO', 'Stream:PrunedHistory',
\json_encode($filterSignalOut($changeSet)),
];
$changeSet = $propDecorator($message, $filterSignalIn($changeSet));
}
if ($signal === 'iterator') {
$changeSet[] = ['SIGEND', 'Stream:End', microtime(),];
yield $type => $apply($changeSet, $props);
}
}
}
function _f($F = null) {return is_callable($F) ? $F : function(){};}
function _i() {return _m('iterator');}
function _m($signal, $message = null) {return [$signal ?? 'iterator',$message];}
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).
Version System time (s) User time (s) Memory (MiB) 7.3.1 0.007 0.007 16.80 7.3.0 0.003 0.007 17.02 7.2.13 0.008 0.004 17.06 7.2.12 0.005 0.005 17.08 7.2.11 0.003 0.009 17.16 7.2.10 0.009 0.006 17.13 7.2.9 0.006 0.006 17.04 7.2.8 0.003 0.008 17.08 7.2.7 0.011 0.003 17.20 7.2.6 0.014 0.000 17.12 7.2.5 0.004 0.011 17.04 7.2.4 0.003 0.010 17.34 7.2.3 0.009 0.009 17.95 7.2.2 0.008 0.009 17.66 7.2.1 0.009 0.011 17.83 7.2.0 0.009 0.008 17.70 7.1.25 0.007 0.003 15.80 7.1.15 0.016 0.005 17.30 7.1.14 0.015 0.015 17.25 7.1.13 0.017 0.013 17.27 7.1.12 0.013 0.010 16.86 7.1.11 0.008 0.013 16.68 7.1.10 0.008 0.015 16.71 7.1.9 0.014 0.010 16.42 7.1.8 0.009 0.008 16.45 7.1.7 0.062 0.009 15.49 7.1.6 0.030 0.008 33.70 7.1.5 0.022 0.015 33.06 7.1.4 0.025 0.013 33.04 7.1.3 0.029 0.012 33.00 7.1.2 0.045 0.012 33.22 7.1.1 0.013 0.007 14.96 7.1.0 0.009 0.012 15.09
preferences:dark mode live preview
22.26 ms | 401 KiB | 5 Q