MCPcopy Create free account
hub / github.com/NGSolve/ngsolve / Timing

Class Timing

python/timing.py:5–104  ·  view source on GitHub ↗

Class for timing analysis of performance critical functions. Some classes export a C++ function as __timing__, which returns a map of performance critical parts with their timings. The class can save these maps, load them and compare them. It can be saved as a benchmark to be compared against.

Source from the content-addressed store, hash-verified

3from ngsolve import TaskManager
4
5class Timing():
6 """
7Class for timing analysis of performance critical functions. Some
8classes export a C++ function as __timing__, which returns a map
9of performance critical parts with their timings. The class can save
10these maps, load them and compare them. It can be saved as a benchmark
11to be compared against.
12
132 overloaded __init__ functions:
14
151. __init__(name,obj,parallel=True,serial=True)
162. __init__(filename)
17
18Parameters
19----------
20
21name (str): Name for the timed class (for output formatting and
22 saving/loading of results)
23obj (NGSolve object): Some NGSolve class which has the __timing__
24 functionality implemented. Currently supported classes:
25 FESpace
26filename (str): Filename to load a previously saved Timing
27parallel (bool=True): Time in parallel (using TaskManager)
28serial (bool=True): Time not in parallel (not using TaskManager)
29
30"""
31 def __init__(self,name=None,obj=None,filename=None,parallel=True,serial=True):
32 assert (not name and not obj and filename) or (name and obj and not filename)
33 if filename:
34 myself = pickle.load(open(filename,"rb"))
35 self.timings = myself.timings
36 self.name = myself.name
37 self.timings_par = myself.timings_par
38 else:
39 if serial:
40 self.timings = obj.__timing__()
41 else:
42 self.timings = None
43 if parallel:
44 with TaskManager():
45 self.timings_par = obj.__timing__()
46 else:
47 self.timings_par = None
48 self.name = name
49
50 def __str__(self):
51 string = "Timing for " + self.name + ":"
52 if self.timings:
53 for key, value in self.timings:
54 string += "\n" + key + ": " + value
55 if self.timings_par:
56 for key, value in self.timings_par:
57 string += "\n" + key + " parallel: " + value
58 return string
59
60 def Save(self, folder):
61 """ Saves the pickled results in folder 'folder' """
62 if not os.path.exists(folder):

Callers 6

CompareToMethod · 0.70
FinalizeUpdateMethod · 0.50
UpdateMethod · 0.50
UpdateMethod · 0.50
timings.pyFile · 0.50
timing.pyFile · 0.50

Calls

no outgoing calls

Tested by

no test coverage detected