tux icon indicating copy to clipboard operation
tux copied to clipboard

Python optimization

Open tuxgitbot[bot] opened this issue 1 year ago • 5 comments

Figure out how to optimize where possible at a lower level and explore areas for improvement

tuxgitbot[bot] avatar Sep 07 '24 02:09 tuxgitbot[bot]

  • https://stackify.com/how-to-optimize-python-code/
  • https://wiki.python.org/moin/PythonSpeed/PerformanceTips
  • https://www.reddit.com/r/Python/comments/19789aq/memory_optimization_techniques_for_python/
  • https://people.duke.edu/~ccc14/sta-663/MakingCodeFast.html
  • https://www.softformance.com/blog/how-to-speed-up-python-code/
  • https://www.reddit.com/r/Python/comments/sekrzq/how_to_optimize_python_code/
  • https://www.datacamp.com/tutorial/optimization-in-python
  • https://www.python.org/doc/essays/list2str/
  • https://medium.com/@quanticascience/performance-optimization-in-python-e8a497cdaf11
  • https://granulate.io/blog/optimizing-python-why-python-is-slow-optimization-methods/
  • https://www.geeksforgeeks.org/optimization-tips-python-code/

kzndotsh avatar Sep 07 '24 02:09 kzndotsh

Not sure if this is mentioned in one of those links, but you can use python3 -m cProfile main.py to profile a given file, or use the @profile decorator from profilehooks to profile a given function

make sure you don't spend to much time optimizing things that are negligible to the rest of the program

arutonee1 avatar Sep 07 '24 13:09 arutonee1

Also, here's a really simple (untested) decorator that logs the runtime of a function after it's run. With a few project-specific modifications it may be useful

import time
def time_fn[F](fn: F) -> F:
    def out(*args, **kwargs):
        start = time.perf_counter()
        fn(*args, **kwargs)
        end = time.perf_counter()
        logger.log(f'{fn.__name__} took {end - start} seconds')
    return out

arutonee1 avatar Sep 07 '24 13:09 arutonee1

Hi @kzndotsh is this issue still open, if yes then what is the requirement would like to contribute on this.

Nandini1071 avatar Sep 21 '24 11:09 Nandini1071

Hi @kzndotsh is this issue still open, if yes then what is the requirement would like to contribute on this.

Yes, it's still open. What do you mean by "requirement"? The issue is pretty wide open more as a discussion at the moment I suppose so I'm open to any direction/small changes or other issues can be made.

kzndotsh avatar Sep 21 '24 13:09 kzndotsh