xaizek / etabench (License: GPLv3) (since 2022-09-08)
Benchmark for algorithms that compute I/O ETA
Commit 67c268da8e19e86e4fd93ecca88fee6237b8c796

Use Window helper in GravityAlg
Author: xaizek
Author date (UTC): 2022-12-30 17:30
Committer name: xaizek
Committer date (UTC): 2022-12-30 17:30
Parent(s): 8317f9362840437a71bd9d4e2376a4006ea76f7e
Signing key: 99DC5E4DB05F6BE2
Tree: f897a2a8fb9de439ee708536da7a16a0b5561736
File Lines added Lines deleted
src/algs.cpp 4 12
src/algs.hpp 6 2
File src/algs.cpp changed (mode: 100644) (index 49fe0ba..1fae56c)
... ... SwitchAlg::estimate(int current, int total, int time)
300 300 return time - it->second; return time - it->second;
301 301 } }
302 302
303 GravityAlg::GravityAlg() : speeds(-1, &indexWeight)
304 { }
305
303 306 void void
304 307 GravityAlg::reset() GravityAlg::reset()
305 308 { {
 
... ... GravityAlg::estimate(int current, int total, int time)
319 322
320 323 int lastTimeElapsed = time - lastTime; int lastTimeElapsed = time - lastTime;
321 324
322 speeds.push_back(float(current - lastProgress)/lastTimeElapsed);
323
324 // Scales are 1/s, 2/s, ..., speeds.size()/s
325 // Where s = 1 + 2 + ... speeds.size()
326 // They sum to 1.
327 float scaleDiv = (1 + speeds.size())*speeds.size()/2.0f;
328
329 float v = 0;
330 for (int i = 0; i < (int)speeds.size(); ++i) {
331 float scaleFactor = (i + 1)/scaleDiv;
332 v += scaleFactor*speeds[i];
333 }
325 float v = speeds.update(float(current - lastProgress)/lastTimeElapsed);
334 326
335 327 const float mass = (lastTime == 0 ? 1.0f : 4.0f); const float mass = (lastTime == 0 ? 1.0f : 4.0f);
336 328 const float maxSpeedCoeff = 0.25f; const float maxSpeedCoeff = 0.25f;
File src/algs.hpp changed (mode: 100644) (index 9ab7ed0..8b10a13)
... ... class Window
30 30 using weight_f = std::function<float(int idx, float lastWeight)>; using weight_f = std::function<float(int idx, float lastWeight)>;
31 31
32 32 public: public:
33 // Pass in negative size for unlimited window size.
33 34 Window(int size, weight_f weight) : size(size), weight(weight) Window(int size, weight_f weight) : size(size), weight(weight)
34 35 { } { }
35 36
 
... ... public:
41 42 { {
42 43 // Emulating circular buffer. // Emulating circular buffer.
43 44 data.push_back(datum); data.push_back(datum);
44 if ((int)data.size() > size) {
45 if ((int)data.size() == size) {
45 46 data.erase(data.cbegin()); data.erase(data.cbegin());
46 47 } }
47 48 } }
 
... ... private:
212 213
213 214 class GravityAlg : public EtaAlg class GravityAlg : public EtaAlg
214 215 { {
216 public:
217 GravityAlg();
218
215 219 public: public:
216 220 virtual std::string getName() const override virtual std::string getName() const override
217 221 { return "Gravity"; } { return "Gravity"; }
 
... ... private:
225 229 int lastTime; int lastTime;
226 230 float avgProgressRate; float avgProgressRate;
227 231 float avgSeekRate; float avgSeekRate;
228 std::vector<float> speeds;
232 Window speeds;
229 233 }; };
230 234
231 235 class FirefoxAlg : public EtaAlg class FirefoxAlg : public EtaAlg
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/etabench

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/etabench

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master