diff --git a/Trajectories/Tests/perf_tests.json b/Trajectories/Tests/perf_tests.json index d4ee73484c028fece1c6bc1aae02bd2567411add..b91137ca3bb9ad586df6f5082bb95a82ca488e7f 100644 --- a/Trajectories/Tests/perf_tests.json +++ b/Trajectories/Tests/perf_tests.json @@ -24,6 +24,7 @@ "command": [ "$src_dir/Trajectories/trajectories.py", "$PWD/Perf_cost_function/segments_cost_functions.gt" - ] - } + ], + "exclude_cmp": ["timings.txt"] + } } diff --git a/Trajectories/trajectories.py b/Trajectories/trajectories.py index 46b4e3207b68d0b79c622664297b7212e0d47532..1233d8056d5dff9434a3f7d421d35f2c693dd0dc 100755 --- a/Trajectories/trajectories.py +++ b/Trajectories/trajectories.py @@ -18,6 +18,7 @@ import json import sys import report_graph import numpy as np +import time def new_traj(ind_traj, traj_prop, n, traj_vert_ind): """Assign new trajectory to vertex index n.""" @@ -27,6 +28,8 @@ def new_traj(ind_traj, traj_prop, n, traj_vert_ind): traj_vert_ind.append([n]) return ind_traj +t0 = time.perf_counter() +timings_file = open("timings.txt", "w") if len(sys.argv) != 2: sys.exit("Required argument: input-graph") g = graph_tool.load_graph(sys.argv[1]) print("Input graph:") @@ -34,6 +37,9 @@ print("Number of vertices:", g.num_vertices()) print("Number of edges:", g.num_edges()) print("Internal properties:") g.list_properties() +t1 = time.perf_counter() +timings_file.write(f'Loading done in {t1 - t0:.0f} s\n') +t0 = t1 if "cost_function" in g.edge_properties: closest_succ = g.new_vertex_property('int') @@ -55,6 +61,9 @@ else: # This happens if there are only isolated segments. print("No cost values in the input file.") +t1 = time.perf_counter() +timings_file.write(f'closest_succ defined in {t1 - t0:.0f} s\n') +t0 = t1 traj_prop = g.new_vertex_property('int', val = - 1) # Trajectory index to which a segment belongs. - 1 means the segment # does not belong yet to any trajectory. The trajectory index is also @@ -144,6 +153,9 @@ for n in topology.topological_sort(g): # traj_prop[n] != - 1 +t1 = time.perf_counter() +timings_file.write(f'traj_prop defined in {t1 - t0:.0f} s\n') +t0 = t1 print("Number of trajectories: ", len(traj_vert_ind)) # We have trajectories as lists of vertex indices. Now construct @@ -173,6 +185,10 @@ for t in traj_vert_ind: traj_segm.append(list_segm) expanded_traj.append(list_eddies_traj) +t1 = time.perf_counter() +timings_file.write(f'traj_segm and expanded_traj defined in {t1 - t0:.0f} s\n') +t0 = t1 + # Save: with open("traj_segm.json", "w") as outfile: @@ -185,4 +201,6 @@ with open("expanded_traj.json", "w") as outfile: outfile, separators = (',', ':')) print("Created expanded_traj.json.") +t1 = time.perf_counter() +timings_file.write(f'Saving done in {t1 - t0:.0f} s\n') print('Done')