proxmox-rrd: avoid expensive modulo (%) inside loop
Modulo is very slow, so we try to avoid it inside loops. Signed-off-by: Dietmar Maurer <dietmar@proxmox.com> Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
parent
ec08247e5c
commit
5885767b91
|
@ -153,8 +153,7 @@ impl RRA {
|
||||||
if let Some(v) = data[i] {
|
if let Some(v) = data[i] {
|
||||||
self.data[index] = v;
|
self.data[index] = v;
|
||||||
}
|
}
|
||||||
index += 1;
|
index += 1; if index >= self.data.len() { index = 0; }
|
||||||
if index >= self.data.len() { index = 0; }
|
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -171,7 +170,7 @@ impl RRA {
|
||||||
let mut index = ((t/reso) % num_entries) as usize;
|
let mut index = ((t/reso) % num_entries) as usize;
|
||||||
for _ in 0..num_entries {
|
for _ in 0..num_entries {
|
||||||
t += reso;
|
t += reso;
|
||||||
index = (index + 1) % (num_entries as usize);
|
index += 1; if index >= self.data.len() { index = 0; }
|
||||||
if t < min_time {
|
if t < min_time {
|
||||||
self.data[index] = f64::NAN;
|
self.data[index] = f64::NAN;
|
||||||
} else {
|
} else {
|
||||||
|
@ -251,7 +250,8 @@ impl RRA {
|
||||||
list.push(Some(value));
|
list.push(Some(value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
t += reso; index = (index + 1) % (num_entries as usize);
|
t += reso;
|
||||||
|
index += 1; if index >= self.data.len() { index = 0; }
|
||||||
}
|
}
|
||||||
|
|
||||||
(start, reso, list)
|
(start, reso, list)
|
||||||
|
|
Loading…
Reference in New Issue