mirror of https://github.com/aria2/aria2
2008-08-01 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Avoid repeated call of gettimeofday() when calculating speed. * src/SpeedCalc.cc * src/SpeedCalc.hpull/1/head
parent
dfe3b9bf15
commit
6ccefc2dbc
|
@ -1,3 +1,9 @@
|
|||
2008-08-01 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||
|
||||
Avoid repeated call of gettimeofday() when calculating speed.
|
||||
* src/SpeedCalc.cc
|
||||
* src/SpeedCalc.h
|
||||
|
||||
2008-08-01 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||
|
||||
Removed writable check when socket's send buffer is full in BitTorrent
|
||||
|
|
|
@ -59,12 +59,12 @@ void SpeedCalc::reset() {
|
|||
}
|
||||
|
||||
unsigned int SpeedCalc::calculateSpeed() {
|
||||
uint64_t milliElapsed = cpArray[sw].differenceInMillis();
|
||||
int64_t milliElapsed = cpArray[sw].differenceInMillis();
|
||||
if(milliElapsed) {
|
||||
unsigned int speed = lengthArray[sw]*1000/milliElapsed;
|
||||
prevSpeed = speed;
|
||||
maxSpeed = std::max(speed, maxSpeed);
|
||||
if(isIntervalOver()) {
|
||||
if(isIntervalOver(milliElapsed)) {
|
||||
changeSw();
|
||||
}
|
||||
return speed;
|
||||
|
@ -74,12 +74,12 @@ unsigned int SpeedCalc::calculateSpeed() {
|
|||
}
|
||||
|
||||
unsigned int SpeedCalc::calculateSpeed(const struct timeval& now) {
|
||||
uint64_t milliElapsed = cpArray[sw].differenceInMillis(now);
|
||||
int64_t milliElapsed = cpArray[sw].differenceInMillis(now);
|
||||
if(milliElapsed) {
|
||||
unsigned int speed = lengthArray[sw]*1000/milliElapsed;
|
||||
prevSpeed = speed;
|
||||
maxSpeed = std::max(speed, maxSpeed);
|
||||
if(isIntervalOver()) {
|
||||
if(isIntervalOver(milliElapsed)) {
|
||||
changeSw();
|
||||
}
|
||||
return speed;
|
||||
|
@ -101,6 +101,11 @@ bool SpeedCalc::isIntervalOver() const {
|
|||
return nextInterval <= cpArray[sw].difference();
|
||||
}
|
||||
|
||||
bool SpeedCalc::isIntervalOver(int64_t milliElapsed) const
|
||||
{
|
||||
return nextInterval <= milliElapsed/1000;
|
||||
}
|
||||
|
||||
void SpeedCalc::changeSw() {
|
||||
lengthArray[sw] = 0;
|
||||
cpArray[sw].reset();
|
||||
|
|
|
@ -52,6 +52,9 @@ private:
|
|||
time_t nextInterval;
|
||||
|
||||
bool isIntervalOver() const;
|
||||
|
||||
bool isIntervalOver(int64_t milliElapsed) const;
|
||||
|
||||
void changeSw();
|
||||
public:
|
||||
SpeedCalc() {
|
||||
|
|
Loading…
Reference in New Issue