Skip to content

NoMod-Programming/py-utility

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

py-utility

Utility functions for managing and monitoring python resources.

installation

pip install py-utility

Decorator Function

memoryit

memoryit returns the total memory used by the function at runtime in bytes.
Example Code:

from pyutility import memoryit
@memoryit
def prime_check(x):
  for i in range(2, x):
    if x % i == 0:
      return False
  return True

limit_memory

limit_memory limits the memory consumption of function at runtime. It takes the limit in MB. You will find unexpected behaviour if too low value is set. The default value is 25 MB. It is throw MemoryError if it exceeds the limit.
Example Code:

from pyutility import limit_memory
@limit_memory(30)
def prime_check(x):
  for i in range(2, x):
    if x % i == 0:
      return False
  return True

timeit

timeit returns the total time take to execute the function in seconds.
Example Code:

from pyutility import timeit
@timeit
def prime_check(x):
  for i in range(2, x):
    if x % i == 0:
      return False
  return True

limit_time

limit_time limits the time used to execute the function. It takes limit as seconds. The default value is 10 seconds. It throws TimeoutError if it exceeds the limit.
Example Code:

from pyutility import limit_time
@limit_time(30)
def prime_check(x):
  for i in range(2, x):
    if x % i == 0:
      return False
  return True

Contribution

All contributions are welcomed. If it is a bug fix or new feature, creating new issue is highly recommend before any pull request.

About

Utility functions for managing and monitoring python resources.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 100.0%