1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2024-12-20 15:40:26 +00:00

devmods:: rulegen-tests:: time measuring improvements (movecount and attempts)

This commit is contained in:
Zeno Rogue 2021-11-01 17:14:01 +01:00
parent 1e2ffd611c
commit 1a74241cd9
2 changed files with 54 additions and 7 deletions

View File

@ -561,11 +561,38 @@ void test_current(string tesname) {
println(hlog, "CSV; failed to convert ", tesname);
return;
}
if(flags & w_known_structure) {
dynamicval<flagtype> f(rulegen::flags, sub_rulegen_flags);
prepare_rules();
alt_treestates = treestates;
pointer_indices.clear();
}
int tstart = SDL_GetTicks();
int attempts = 0;
double max_time = 0, avg_time = 0, variance_time = 0;
auto begin = clock(); // std::chrono::high_resolution_clock::now();
auto last = begin;
try {
generate_rules();
while(!attempts) { // || (clock() < begin + 0.1 * CLOCKS_PER_SEC && attempts < 1000)) {
if(true) {
rulegen::delete_tmap();
rulegen::clear_all();
last = clock();
rulegen::movecount = 0;
}
generate_rules();
auto cur = clock();
double t = (cur - last) * 1. / CLOCKS_PER_SEC;
last = cur;
if(t > max_time) max_time = t;
avg_time += t;
variance_time += t * t;
attempts++;
}
status = "ACC";
message = "OK";
ok = true;
@ -590,6 +617,20 @@ void test_current(string tesname) {
status = "PRE";
message = e.what();
}
if(!attempts) {
auto cur = clock();
double t = (cur - last) * 1. / CLOCKS_PER_SEC;
avg_time += t; variance_time += t*t; max_time = t;
attempts = 1;
}
avg_time /= attempts;
variance_time /= attempts;
variance_time -= avg_time * avg_time;
if(attempts > 1) {
variance_time *= attempts;
variance_time /= (attempts-1);
}
auto end = clock(); // std::chrono::high_resolution_clock::now();
@ -655,6 +696,10 @@ void test_current(string tesname) {
case 'T': Out("T", tstart / 1000.);
// case 'P': Out("Tp", std::chrono::duration_cast<std::chrono::nanoseconds>(end-begin).count() / 1000000000.);
case 'P': Out("Tp", (end-begin) * 1. / CLOCKS_PER_SEC);
case 'N': Out("attempts", attempts);
case 'M': Out("maxtime", max_time);
case 'E': Out("avgtime", avg_time);
case 'V': Out("vartime", variance_time);
case 'y': Out("tree", isize(treestates));
case 'a': Out("amin;amax", lalign(0, areas[0], ";", areas.back()));
case 'h': Out("shapes", isize(arb::current.shapes));

View File

@ -79,6 +79,8 @@ static const flagtype w_bfs = Flag(17); /*< compute distances using BFS */
EX flagtype flags = 0;
EX int64_t movecount;
#if HDR
struct tcell* tmove(tcell *c, int d);
@ -104,11 +106,11 @@ struct tcell {
/** sometimes we find out that multiple tcells represent the same actual cell -- in this case we unify them; unified_to is used for the union-find algorithm */
walker<tcell> unified_to;
int degree() { return type; }
connection_table<tcell> c;
tcell*& move(int d) { return c.move(d); }
tcell*& modmove(int d) { return c.modmove(d); }
tcell* cmove(int d) { return tmove(this, d); }
tcell* cmodmove(int d) { return tmove(this, c.fix(d)); }
connection_table<tcell> c;
tcell*& move(int d) { movecount++; return c.move(d); }
tcell*& modmove(int d) { movecount++; return c.modmove(d); }
tcell* cmove(int d) { movecount++; return tmove(this, d); }
tcell* cmodmove(int d) { movecount++; return tmove(this, c.fix(d)); }
tcell() { }
};