Explore useful Automation Techniques with Powershell on Windows
Introduction We will list few interesting automation techniques with powershell…
July 30, 2019
This is regarding the timeit implementation in python. The basic requirement comes when you want to see how much time your methods are taking. And, on the basis on those numbers you would want to take some action in optimising them.
You should use it on almost every method, and you can use any graphical tool to get the statistics per method. And, you can identify the area which needs improvement.
Below is one implementation of timeit functionality, which implements it as a decorator.
"""
Decorator for taking performance numbers
"""
import time
def perf(method):
"""
A decorator for fetching time taken by methods
"""
def timed(*args, **kw):
# get start time
start_time = time.time()
# calling the method
result = method(*args, **kw)
# get end time
end_time = time.time()
stats = {}
stats['method'] = f'{method.__module__}::{method.__qualname__}'
stats['timetaken'] = '%2.2f' % int((end_time-start_time)*1000)
print(f'Performance numbers, method={stats["method"]}, timetaken={stats["timetaken"]}')
return result
return timed
@perf
def test1():
print('Im in method test1')
time.sleep(2);
test1()
# Output
Performance numbers, method=__main__::test1, timetaken=2001.00
You can change logging with whatever suits you. I have used print(), but you can use logger to log this in your standard log stream.
Introduction We will list few interesting automation techniques with powershell…
Being a drupal user from last around 5 years, I used to know small codes for…
This library is ES6, promise compatible. Or, in your package.json file, include…
Note: This is based on bootstrap-4 If you are using multi column design in your…
Introduction In this post, we will learn about some of Best practices while…
Introduction In last post, we saw How to read CSV with Headers into Dictionary…
Introduction In this post we will see following: How to schedule a job on cron…
Introduction There are some cases, where I need another git repository while…
Introduction In this post, we will see how to fetch multiple credentials and…
Introduction I have an automation script, that I want to run on different…
Introduction I had to write a CICD system for one of our project. I had to…
Introduction Java log4j has many ways to initialize and append the desired…