-3

as the title, how to know? is task manager the best way as my friend told me? I code in python..

I'm new here sorry if my question was in the wrong place.

New contributor
Jawad is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
3
  • 1
    What problem are you trying to solve? i.e. why do you need to know these things – Philip Kendall Jun 10 at 22:25
  • @Philip Kendal must ppl know the specification of your app tho :)! – Jawad Jun 10 at 22:49
  • Languages that provide tight control over resources, such as C, C++ may provide such estimations. Be sure you need them. – h22 Jun 11 at 10:05
0

It is not generally possible to measure resource requirements in advance, so you'll have to test under a representative workload.

While the task manager can provide highly accurate results for a point in time, you're likely more interested in total CPU usage and maximum memory usage. On the Linux command line, you can easily gather these statistics with the time command.

Note that any such measurements will be inaccurate if your Python code launches additional processes. This is somewhat common in Python programs with high CPU usage, since forking additional processes is the only way to gain parallelism in CPython, i.e. to use more than one CPU.

In some cases, calculating memory requirements is possible though. If your program processes a single large data structure, the size of this structure will likely dominate memory usage. For example, an image processing script will likely spend most of its memory on the image buffer.

Python also has some builtin functions for monitoring resource usage. The os.times() function can return the used CPU time, including CPU used by subprocesses. The resource.getrusage() function can return information about memory usage, but is very low-level.

Not the answer you're looking for? Browse other questions tagged or ask your own question.