From 1a74241cd949f6de54bf1d3edf977bcb17dbd704 Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Mon, 1 Nov 2021 17:14:01 +0100 Subject: [PATCH] devmods:: rulegen-tests:: time measuring improvements (movecount and attempts) --- devmods/rulegen-tests.cpp | 49 +++++++++++++++++++++++++++++++++++++-- rulegen.cpp | 12 ++++++---- 2 files changed, 54 insertions(+), 7 deletions(-) diff --git a/devmods/rulegen-tests.cpp b/devmods/rulegen-tests.cpp index 0f95baf3..6b9aa3b3 100644 --- a/devmods/rulegen-tests.cpp +++ b/devmods/rulegen-tests.cpp @@ -561,11 +561,38 @@ void test_current(string tesname) { println(hlog, "CSV; failed to convert ", tesname); return; } - + + if(flags & w_known_structure) { + dynamicval 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(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)); diff --git a/rulegen.cpp b/rulegen.cpp index c21fd4fb..49779a0d 100644 --- a/rulegen.cpp +++ b/rulegen.cpp @@ -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 unified_to; int degree() { return type; } - connection_table 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 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() { } };