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

Use Window helper in WindowAlg
Author: xaizek
Author date (UTC): 2022-12-30 17:22
Committer name: xaizek
Committer date (UTC): 2022-12-30 17:22
Parent(s): 3bf284af74c1ef876c928db39c9ca98e87ac87c2
Signing key: 99DC5E4DB05F6BE2
Tree: a18f709b3182dd15fdfb79e452c20cf29af3f13c
File Lines added Lines deleted
src/algs.cpp 18 19
src/algs.hpp 3 2
File src/algs.cpp changed (mode: 100644) (index 68957f4..49fe0ba)
29 29 #include "utils/float.hpp" #include "utils/float.hpp"
30 30 #include "core.hpp" #include "core.hpp"
31 31
32 struct FactorWeight
33 {
34 float factor;
35
36 FactorWeight(float factor) : factor(factor)
37 { }
38
39 float operator()(int idx, float lastWeight) const
40 {
41 return (idx == 0 ? 1.0f : lastWeight*factor);
42 }
43 };
44
32 45 template <float factor> template <float factor>
33 46 float float
34 47 factorWeight(int idx, float lastWeight) factorWeight(int idx, float lastWeight)
35 { return (idx == 0 ? 1.0f : lastWeight*factor); }
48 { return FactorWeight(factor)(idx, lastWeight); }
36 49
37 50 static float static float
38 51 indexWeight(int idx, float lastWeight) indexWeight(int idx, float lastWeight)
 
... ... SlownessAlg::estimate(int current, int total, int time)
465 478 } }
466 479
467 480 WindowAlg::WindowAlg(int windowSize, float alpha) : WindowAlg::WindowAlg(int windowSize, float alpha) :
468 windowSize(windowSize), alpha(alpha)
481 windowSize(windowSize),
482 alpha(alpha),
483 speeds(windowSize, FactorWeight(alpha))
469 484 { } { }
470 485
471 486 std::string std::string
 
... ... WindowAlg::estimate(int current, int total, int time)
488 503 return 0; return 0;
489 504 } }
490 505
491 speeds.push_back(float(current - lastProgress)/(time - lastTime));
492
493 if ((int)speeds.size() > windowSize) {
494 speeds.erase(speeds.cbegin());
495 }
496
497 float v = 0;
498 float totalWeight = 0;
499 float weight = alpha;
500 for (int i = 0; i < (int)speeds.size(); ++i) {
501 v += weight*speeds[i];
502 totalWeight += weight;
503 weight *= alpha;
504 }
505
506 v /= totalWeight;
507
506 float v = speeds.update(float(current - lastProgress)/(time - lastTime));
508 507 if (floatEq(v, 0)) { if (floatEq(v, 0)) {
509 508 return lastEta + time - lastTime; return lastEta + time - lastTime;
510 509 } }
File src/algs.hpp changed (mode: 100644) (index bead426..9ab7ed0)
18 18 #ifndef ETABENCH__ALGS_HPP__ #ifndef ETABENCH__ALGS_HPP__
19 19 #define ETABENCH__ALGS_HPP__ #define ETABENCH__ALGS_HPP__
20 20
21 #include <functional>
21 22 #include <map> #include <map>
22 23 #include <memory> #include <memory>
23 24 #include <vector> #include <vector>
 
26 27
27 28 class Window class Window
28 29 { {
29 using weight_f = float (*)(int idx, float lastWeight);
30 using weight_f = std::function<float(int idx, float lastWeight)>;
30 31
31 32 public: public:
32 33 Window(int size, weight_f weight) : size(size), weight(weight) Window(int size, weight_f weight) : size(size), weight(weight)
 
... ... private:
306 307 int lastTime; int lastTime;
307 308 int lastProgress; int lastProgress;
308 309 int lastEta; int lastEta;
309 std::vector<int> speeds;
310 Window speeds;
310 311 }; };
311 312
312 313 class ExponentialAlg : public EtaAlg class ExponentialAlg : 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