Joe LaFata committed ffa2efe

documentation updates

Comments (0)

Files changed (4)

-This is the main class to extend when using unitbench.
+This is the main class to extend when using unitbench to write benchmarks similar to unit tests.
 .. autoclass:: unitbench.Benchmark
    :members: input, repeats, setup, teardown, warmup
       This should generally not be overloaded.  It runs the benchmark functions
       that are found in the child class.  Benchmark functions are discovered by
       looking for methods starting with **bench**.
+This is the function profiler.  Rather than a general profiler which profiles every function,
+this profiles specific functions as you choose.  It is used as a function decorator applied to
+functions you're interested in seeing the performance.  It can track the parameters used to
+call the given function also.  If your function is slow for a given input, that could be tracked
+using the FunctionProfiler.
+Here is a quick example::
+   fp = FunctionProfiler()
+   @fp
+   def fib(n):
+       if n == 1 or n == 0:
+           return n
+       return fib(n - 1) + fib(n - 2)
+   fib(15)
+   print(fp)
+.. autoclass:: unitbench.FunctionProfiler
+   :members: __str__, write_results, reset
 This is the default reporter for unitbench.  It will it writes
 # built documents.
 # The short X.Y version.
-version = '0.1'
+version = '1.0'
 # The full version, including alpha/beta/rc tags.
-release = '0.1'
+release = '1.0'
 # The language for content autogenerated by Sphinx. Refer to documentation
 # for a list of supported languages.


 Then it produces this output:::
-   Values,Naive Primes,Sieve Of Eratosthenes
-   100,7.8841602472e-05,2.5209759515e-05
-   1000,0.000797913330243,0.000192320436854
-   10000,0.010098568763,0.00206587345078
-   100000,0.155457692961,0.0319632515729
+   Name,Value,Call Count,Wall Minimum,Wall Maximum,Wall Average,Wall Standard Deviation,Wall Variance
+   Naive Primes,100,7,5.79357147217e-05,6.19888305664e-05,5.91278076172e-05,1.26159253648e-06,1.5916157281e-12
+   Naive Primes,1000,7,0.000690937042236,0.000741958618164,0.000701870237078,1.66158757018e-05,2.76087325337e-10
+   Naive Primes,10000,7,0.00882005691528,0.00918817520142,0.00898504257202,0.000157213352588,2.47160382319e-08
+   Naive Primes,100000,7,0.139157056808,0.139923095703,0.139575345176,0.00023467537773,5.50725329125e-08
+   Sieve Of Eratosthenes,100,7,1.81198120117e-05,2.59876251221e-05,1.98568616595e-05,2.52226537726e-06,6.36182263332e-12
+   Sieve Of Eratosthenes,1000,7,0.000169038772583,0.000175952911377,0.000171593257359,2.83740801125e-06,8.05088422233e-12
+   Sieve Of Eratosthenes,10000,7,0.00182700157166,0.00192213058472,0.00187890870231,3.14177212374e-05,9.87073207751e-10
+   Sieve Of Eratosthenes,100000,7,0.0235598087311,0.0260169506073,0.0249668530055,0.000736537686839,5.42487764134e-07
                        end_user_system[1] - start_user_system[1])
 class FunctionProfiler(BenchBase):
+    """
+    The constructor of the FunctionProfiler takes 3 arguments.  All
+    parameters are optional.
+    ================ =============================================================
+    Parameter        Definition
+    ================ =============================================================
+    repeats          Number of times the function will be run per call.  If
+                     this is greater than 1, every call to the function will
+                     cause the function to be called multiple times. [Default: 1]
+    warmup           Number of times to run the function before recording
+                     runtimes. [Default: 0]
+    track_parameters If parameters should be tracked while calling the function.
+                     If parameters are being tracked and you call func(1) and
+                     func(2), that would create 2 separate entries in the output
+                     (1 for func(1) and 1 for func(2)).  If track_prameters is off
+                     it calls to func(1) and func(2) will be tracked together.
+                     [Default: False]
+    ================ =============================================================
+    """
     __slots__ = ["repeats", "warmup", "results", "track_parameters"]
         return wrapper
     def __str__(self):
+        """Get the string representation of write_results"""
         stream = StringIO()
         reporter = ConsoleReporter(output_stream=stream,
         return output
     def write_results(self, reporter=None):
+        """Write the results that are stored in this function profiler.  Pass
+        in a reporter to format the output as desired."""
         if reporter == None:
             reporter = ConsoleReporter(group_by=ConsoleReporter.GroupType.FUNCTION)
     def reset(self, repeats=1, warmup=0, track_parameters=False):
+        """Reset the FunctionProfiler back to its original state
+        """
         self.repeats = FunctionProfiler._wrap_int(repeats)
         self.warmup = FunctionProfiler._wrap_int(warmup)
         self.track_parameters = track_parameters
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.