diff options
| author | Kirill Petrashin <kirill8201@yandex.ru> | 2026-04-16 23:02:27 +0300 |
|---|---|---|
| committer | Kirill Petrashin <kirill8201@yandex.ru> | 2026-04-16 23:02:27 +0300 |
| commit | 22b285ffc4345bee05772509a60fb77fb90d16a0 (patch) | |
| tree | d981ffb1951028423fb4c832166b4efde6fe8029 /path.c | |
| parent | 7dfb37936206de02e9a8c0ef5a3e0593aa535cd1 (diff) | |
| download | astar-22b285ffc4345bee05772509a60fb77fb90d16a0.tar.xz | |
Add pathfinding timing
Diffstat (limited to 'path.c')
| -rw-r--r-- | path.c | 23 |
1 files changed, 23 insertions, 0 deletions
@@ -3,6 +3,7 @@ #include <string.h> #include <curses.h> #include <math.h> +#include <time.h> #include <unistd.h> #include "path.h" @@ -13,6 +14,7 @@ #include "config.h" Path (*path_func)(int, Map, size_t **, size_t, size_t, Position, Position, char **, char) = &astar_path; +double path_time = 0; char anim_automatic = 0; @@ -124,6 +126,8 @@ int anim(Map map, size_t width, size_t height, Position start, Position end, Pos //} Path dijkstra_path(int dirs, Map map, size_t **cell_costs, size_t width, size_t height, Position start, Position end, char **visited, char should_anim) { + clock_t tstart = clock(); + anim_automatic = 0; /* The function to use to find neighbours */ @@ -151,6 +155,10 @@ Path dijkstra_path(int dirs, Map map, size_t **cell_costs, size_t width, size_t if (cur.x == end.x && cur.y == end.y) { ppq_free(frontier); cost_free(cost_so_far, height); + + clock_t tend = clock(); + path_time = (tend - tstart) / (double)CLOCKS_PER_SEC; + return path; /* Found path */ } @@ -176,6 +184,8 @@ Path dijkstra_path(int dirs, Map map, size_t **cell_costs, size_t width, size_t path_free(path, height); ppq_free(frontier); cost_free(cost_so_far, height); + clock_t tend = clock(); + path_time = (tend - tstart) / (double)CLOCKS_PER_SEC; return NULL; } } @@ -184,10 +194,14 @@ Path dijkstra_path(int dirs, Map map, size_t **cell_costs, size_t width, size_t path_free(path, height); ppq_free(frontier); cost_free(cost_so_far, height); + clock_t tend = clock(); + path_time = (tend - tstart) / (double)CLOCKS_PER_SEC; return NULL; } Path astar_path(int dirs, Map map, size_t **cell_costs, size_t width, size_t height, Position start, Position end, char **visited, char should_anim) { + clock_t tstart = clock(); + anim_automatic = 0; /* The function to use to find neighbours */ @@ -218,6 +232,10 @@ Path astar_path(int dirs, Map map, size_t **cell_costs, size_t width, size_t hei if (cur.x == end.x && cur.y == end.y) { ppq_free(frontier); cost_free(cost_so_far, height); + + clock_t tend = clock(); + path_time = (tend - tstart) / (double)CLOCKS_PER_SEC; + return path; /* Found path */ } @@ -244,6 +262,8 @@ Path astar_path(int dirs, Map map, size_t **cell_costs, size_t width, size_t hei path_free(path, height); ppq_free(frontier); cost_free(cost_so_far, height); + clock_t tend = clock(); + path_time = (tend - tstart) / (double)CLOCKS_PER_SEC; return NULL; } } @@ -252,6 +272,9 @@ Path astar_path(int dirs, Map map, size_t **cell_costs, size_t width, size_t hei path_free(path, height); ppq_free(frontier); cost_free(cost_so_far, height); + + clock_t tend = clock(); + path_time = (tend - tstart) / (double)CLOCKS_PER_SEC; return NULL; } |
