Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use class instead of static variables for the speed measurement #168

Merged
merged 1 commit into from
Nov 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions lib/cli/Notify.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ abstract class Notify {
protected $_message;
protected $_start;
protected $_timer;
protected $_tick;
protected $_iteration = 0;
protected $_speed = 0;

/**
* Instatiates a Notification object.
Expand Down Expand Up @@ -92,23 +95,21 @@ public function elapsed() {
* @return int The number of ticks performed in 1 second.
*/
public function speed() {
static $tick, $iteration = 0, $speed = 0;

if (!$this->_start) {
return 0;
} else if (!$tick) {
$tick = $this->_start;
} else if (!$this->_tick) {
$this->_tick = $this->_start;
}

$now = microtime(true);
$span = $now - $tick;
$span = $now - $this->_tick;
if ($span > 1) {
$iteration++;
$tick = $now;
$speed = ($this->_current / $iteration) / $span;
$this->_iteration++;
$this->_tick = $now;
$this->_speed = ($this->_current / $this->_iteration) / $span;
}

return $speed;
return $this->_speed;
}

/**
Expand Down