/[escript]/trunk/escript/py_src/benchmark.py
ViewVC logotype

Diff of /trunk/escript/py_src/benchmark.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2168 by caltinay, Mon Dec 15 07:17:47 2008 UTC revision 2169 by caltinay, Wed Dec 17 03:08:58 2008 UTC
# Line 40  from esys.escript import setNumberOfThre Line 40  from esys.escript import setNumberOfThre
40    
41  class BenchmarkSuite(object):  class BenchmarkSuite(object):
42     """     """
43     framework to run a bunch of L{Benchmark}s using the object and creating a     Framework to run a bunch of L{Benchmark}s using the object and creating a
44     table of statistics.     table of statistics.
45    
46     @cvar MAX_LEVEL: maximum number of level in headers for output     @cvar MAX_LEVEL: maximum number of level in headers for output
# Line 48  class BenchmarkSuite(object): Line 48  class BenchmarkSuite(object):
48     MAX_LEVEL=5     MAX_LEVEL=5
49     def __init__(self,name=None):     def __init__(self,name=None):
50         """         """
51         sets up a suite of benchmarks         Sets up a suite of benchmarks.
52    
53         @param name: name of the benchmark suite. If no name is given the class         @param name: name of the benchmark suite. If no name is given the class
54                      name is used.                      name is used.
# Line 64  class BenchmarkSuite(object): Line 64  class BenchmarkSuite(object):
64    
65     def __str__(self):     def __str__(self):
66         """         """
67         returns the name of the benchmark suite         Returns the name of the benchmark suite.
68    
69         @return:  name         @return: the name
70         @rtype: C{str}         @rtype: C{str}
71         """         """
72         return self.__name         return self.__name
73    
74     def addBenchmark(self,benchmark):     def addBenchmark(self,benchmark):
75         """         """
76         adds a L{Benchmark} to the suite         Adds a new L{Benchmark} to the suite.
77    
78         @param benchmark: adds a new L{Benchmark} to the suite         @param benchmark: the benchmark to add
79         @type benchmark: L{Benchmark}         @type benchmark: L{Benchmark}
80         """         """
81         self.__benchmarks.append(benchmark)         self.__benchmarks.append(benchmark)
82    
83     def __len__(self):     def __len__(self):
84         """         """
85         returns the number of benchmarks in the suite         Returns the number of benchmarks in the suite.
86    
87         @return:  number of benchmarks         @return: number of benchmarks
88         @rtype: C{int}         @rtype: C{int}
89         """         """
90         return len(self.__benchmarks)         return len(self.__benchmarks)
91    
92     def __getitem__(self,i):     def __getitem__(self,i):
93         """         """
94         returns the i-th benchmark in the suite through self[i]         Returns the i-th benchmark in the suite through self[i].
95    
96         @param i: index of the requested benchmark         @param i: index of the requested benchmark
97         @type i: C{int}         @type i: C{int}
98         @return:  i-th benchmark         @return: i-th benchmark
99         @rtype: L{Benchmark}         @rtype: L{Benchmark}
100    
101         """         """
# Line 103  class BenchmarkSuite(object): Line 103  class BenchmarkSuite(object):
103    
104     def run(self,scale=1):     def run(self,scale=1):
105         """         """
106         runs all benchmarks         Runs all benchmarks.
107    
108         @param scale: defines the number of (OpenMP) threads to be used. If         @param scale: defines the number of (OpenMP) threads to be used. If
109                       scale is a scalar all benchmarks are run with scale number                       C{scale} is a scalar all benchmarks are run with C{scale}
110                       of threads. If scale is a C{list}, the p-th problem in                       number of threads. If C{scale} is a C{list}, the p-th
111                       each of the benchmarks in the suite is run with scale[p]                       problem in each of the benchmarks in the suite is run with
112                       threads. If scale[p]<1 the p-th problem is omitted.                       C{scale[p]} threads. If C{scale[p]}<1 the p-th problem is
113         @type scale: C{int} or C{list} of C{int}s.                       omitted.
114           @type scale: C{int} or C{list} of C{int}s
115         """         """
116         self.__scale=scale         self.__scale=scale
117         for i in range(len(self)): self[i].run(scale=scale)         for i in range(len(self)): self[i].run(scale=scale)
118    
119     def getHTML(self,filter,level=1):     def getHTML(self,filter,level=1):
120         """         """
121         returns the results of the last benchmark run in HTML format.         Returns the results of the last benchmark run in HTML format.
122    
123         @param filter: filter to be applied to the results         @param filter: filter to be applied to the results
124         @type filter: L{BenchmarkFilter}         @type filter: L{BenchmarkFilter}
# Line 152  class BenchmarkSuite(object): Line 153  class BenchmarkSuite(object):
153    
154  class Benchmark(object):  class Benchmark(object):
155     """     """
156     runs a bunch of similar L{BenchmarkProblem}s with a bunch of L{Options}     Runs a bunch of similar L{BenchmarkProblem}s with a bunch of L{Options}.
157     """     """
158     def __init__(self,name=None,description=None):     def __init__(self,name=None,description=None):
159         """         """
160         sets up a benchmark         Sets up a benchmark.
161    
162         @param name: name of the benchmark. If no name is given the class name         @param name: name of the benchmark. If no name is given the class name
163                      is used.                      is used.
164         @type name: C{str}         @type name: C{str}
165         @param description: description of the benchmark.         @param description: description of the benchmark
166         @type description: C{str} or C{None}         @type description: C{str} or C{None}
167         """         """
168         super(Benchmark,self).__init__()         super(Benchmark,self).__init__()
# Line 177  class Benchmark(object): Line 178  class Benchmark(object):
178    
179     def __str__(self):     def __str__(self):
180         """         """
181         returns the name of the benchmark suite         Returns the name of the benchmark suite.
182    
183         @return:  name         @return: the name
184         @rtype: C{str}         @rtype: C{str}
185         """         """
186         return self.__name         return self.__name
187    
188     def addProblem(self,problem):     def addProblem(self,problem):
189         """         """
190         adds a problem to the benchmark         Adds a problem to the benchmark.
191    
192         @param problem: adds a new problem to the benchmark         @param problem: the problem to be added
193         @type problem: L{BenchmarkProblem}         @type problem: L{BenchmarkProblem}
194         """         """
195         self.__problems.append(problem)         self.__problems.append(problem)
196    
197     def addOptions(self,options):     def addOptions(self,options):
198         """         """
199         adds options to the benchmark         Adds options to the benchmark.
200    
201         @param options: the options to be added to the bechmark. If         @param options: the options to be added to the benchmark. If
202                         options==None they are ignored                         options==None the options are left unchanged.
203         @type options: L{Options}         @type options: L{Options}
204         """         """
205         if options!=None: self.__options.append(options)         if options!=None: self.__options.append(options)
206    
207     def run(self,scale=1):     def run(self,scale=1):
208         """         """
209         runs all problems with all options.         Runs all problems with all options.
210    
211         @param scale: defines the number of (OpenMP) threads to be used. If         @param scale: defines the number of (OpenMP) threads to be used. If
212                       scale is a scalar all benchmarks are run with scale number                       C{scale} is a scalar all benchmarks are run with C{scale}
213                       of threads. If scale is a C{list}, the p-th problem in                       number of threads. If C{scale} is a C{list}, the p-th
214                       each of the benchmarks in the suite is run with scale[p]                       problem in each of the benchmarks in the suite is run with
215                       threads. If scale[p]<1 the p-th problem is omitted.                       C{scale[p]} threads. If C{scale[p]}<1 the p-th problem is
216         @type scale: C{int} or C{list} of C{int}s.                       omitted.
217           @type scale: C{int} or C{list} of C{int}s
218         """         """
219         if isinstance(scale,list):         if isinstance(scale,list):
220             c_max=min(len(scale),len(self.__problems))             c_max=min(len(scale),len(self.__problems))
# Line 244  class Benchmark(object): Line 246  class Benchmark(object):
246    
247     def getHTML(self,filter,level=1):     def getHTML(self,filter,level=1):
248         """         """
249         returns the results of the last benchmark run in HTML format.         Returns the results of the last benchmark run in HTML format.
250    
251         @param filter: filter to be applied to the results         @param filter: filter to be applied to the results
252         @type filter: L{BenchmarkFilter}         @type filter: L{BenchmarkFilter}
# Line 307  class Benchmark(object): Line 309  class Benchmark(object):
309    
310  class BenchmarkProblem(object):  class BenchmarkProblem(object):
311     """     """
312     a benchmark problem that can be run and which returns a list of     Represents a benchmark problem that can be run and which returns a list of
313     characteristics such as timing, MFlops, error, etc.     characteristics such as timing, MFlops, error, etc.
314     """     """
315     def __init__(self,name=None):     def __init__(self,name=None):
316         """         """
317         sets up a benchmark problem         Sets up a benchmark problem.
318    
319         @param name: name of the problem. If no name is given the class name         @param name: name of the problem. If no name is given the class name
320                      is used.                      is used.
# Line 326  class BenchmarkProblem(object): Line 328  class BenchmarkProblem(object):
328    
329     def __str__(self):     def __str__(self):
330         """         """
331         returns the name of the benchmark suite         Returns the name of the benchmark suite.
332    
333         @return:  name         @return: the name
334         @rtype: C{str}         @rtype: C{str}
335         """         """
336         return self.__name         return self.__name
337    
338     def run(self,options=None):     def run(self,options=None):
339         """         """
340         runs the problem and returns a list of run characteristics         Runs the problem and returns a list of run characteristics.
341    
342         @param options: the options that are used for the run. Note that the         @param options: the options that are used for the run. Note that the
343                         number of OpenMP threads is controlled by the                         number of OpenMP threads is controlled by the
# Line 343  class BenchmarkProblem(object): Line 345  class BenchmarkProblem(object):
345         @type options: L{Options}         @type options: L{Options}
346         @return: run characteristics         @return: run characteristics
347         @rtype: any type that can be read by the L{BenchmarkFilter} applied         @rtype: any type that can be read by the L{BenchmarkFilter} applied
348                 to it.                 to it
349         @note: this function has to be overwritten by a particular problem         @note: this function has to be overwritten by a particular problem
350         """         """
351         raise NotImplementedError         raise NotImplementedError
# Line 351  class BenchmarkProblem(object): Line 353  class BenchmarkProblem(object):
353    
354  class BenchmarkFilter(object):  class BenchmarkFilter(object):
355     """     """
356     object to filter the characteristics returned by Benchmark runs.     Object to filter the characteristics returned by Benchmark runs.
357    
358     """     """
359     def __init__(self):     def __init__(self):
360         """         """
361         sets up a filter         Sets up a filter.
362         """         """
363         pass         pass
364    
365     def getResultNames(self):     def getResultNames(self):
366         """         """
367         returns the names of the results produced when run() is called.         Returns the names of the results produced when C{run()} is called.
368    
369         @return: the list of the names to be used when the results of         @return: the list of the names to be used when the results of
370                  the run() call are printed                  the C{run()} call are printed
371         @rtype: C{list} of C{str}         @rtype: C{list} of C{str}
372         @note: this function has to overwritten by a particular problem         @note: this function has to overwritten by a particular problem
373         """         """
# Line 374  class BenchmarkFilter(object): Line 376  class BenchmarkFilter(object):
376    
377     def __call__(self,result):     def __call__(self,result):
378         """         """
379         filters out results returned as characteristics of a problem run         Filters out results returned as characteristics of a problem run.
380    
381         @param result: values to be filtered         @param result: values to be filtered
382         @type result: any type that is produced by the L{BenchmarkProblem}         @type result: any type that is produced by the L{BenchmarkProblem}
# Line 389  class BenchmarkFilter(object): Line 391  class BenchmarkFilter(object):
391    
392  class Options(object):  class Options(object):
393      """      """
394      defines a set of options to be used to run a L{BenchmarkProblem}      Defines a set of options to be used to run a L{BenchmarkProblem}.
395      """      """
396      def __init__(self,name=None):      def __init__(self,name=None):
397         """         """
398         sets up the options         Sets up the options.
399    
400         @param name: name of the option. If no name is given the class name         @param name: name of the option. If no name is given the class name
401                      is used.                      is used.
# Line 407  class Options(object): Line 409  class Options(object):
409    
410      def __str__(self):      def __str__(self):
411         """         """
412         returns the name of the benchmark suite         Returns the name of this options object.
413    
414         @return:  name         @return: the name
415         @rtype: C{str}         @rtype: C{str}
416         """         """
417         return self.__name         return self.__name

Legend:
Removed from v.2168  
changed lines
  Added in v.2169

  ViewVC Help
Powered by ViewVC 1.1.26