unipy.utils.decorator module¶
Docstring for decorator.
Function Decorator¶
Profiler |
|
|---|---|
time_profiler |
Function running time command-line profiler. |
time_logger |
Function running time log profiler. |
profiler |
High level API combining time_profiler & time_logger. |
Commandline printout |
|
|---|---|
job_wrapper |
Command-line line dragging tool. |
Code Translation |
|
|---|---|
Infix |
Function to operator translator. |
infix |
Functional API for |
-
unipy.utils.decorator.time_profiler(func)[source]¶ Print wrapper for time profiling.
This wrapper prints out start, end and elapsed time.
- Parameters
func (Function) – A function to profile.
- Returns
A wrapped function.
- Return type
Function
See also
functools.wrapsdecoratorExamples
>>> import unipy as up >>> @up.time_profiler ... def afunc(i): ... return len(list(range(i))) ... >>> res = afunc(58) (afunc) Start : 2018-06-20 22:11:35.511374 (afunc) End : 2018-06-20 22:11:35.511424 (afunc) Elapsed : 0:00:00.000050 >>> res 58
-
unipy.utils.decorator.time_logger(func)[source]¶ Logging wrapper for time profiling.
This wrapper logs start, end and elapsed time.
- Parameters
func (Function) – A function to profile.
- Returns
A wrapped function.
- Return type
Function
See also
functools.wrapsdecoratorExamples
>>> import unipy as up >>> @up.time_logger ... def afunc(i): ... return len(list(range(i))) ... >>> res = afunc(58) (afunc) Start : 2018-06-20 22:11:35.511374 (afunc) End : 2018-06-20 22:11:35.511424 (afunc) Elapsed : 0:00:00.000050 >>> res 58
-
unipy.utils.decorator.job_wrapper(func)[source]¶ Print wrapper for time profiling.
This wrapper prints out start & end line.
- Parameters
func (Function) – A function to separate print-line job.
- Returns
A wrapped function.
- Return type
Function
See also
functools.wrapsdecoratorExamples
>>> import unipy as up >>> @up.job_wrapper ... def afunc(i): ... return len(list(range(i))) ... >>> afunc(458) ----------- [afunc] START -----------
———– [afunc] END ———–
afunc : 0:00:00.000023
458
-
class
unipy.utils.decorator.Infix(func)[source]¶ Bases:
objectWrapper for define an operator.
This wrapper translates a function to an operator.
- Returns
A wrapped function.
- Return type
Function
See also
functools.partialdecoratorExamples
>>> @Infix ... def add(x, y): ... return x + y ... >>> 5 |add| 6 11 >>> instanceof = Infix(isinstance) >>> 5 |instanceof| int True
-
unipy.utils.decorator.infix(func)[source]¶ A functional API for Infix decorator.
- Returns
A wrapped function.
- Return type
Function
See also
unipy.utils.wrapper.infixExamples
>>> @infix ... def add(x, y): ... return x + y ... >>> 5 |add| 6 11 >>> instanceof = infix(isinstance) >>> 5 |instanceof| int True