Performance Between Django and Raw Python

I was wondering what is the performance difference between using simple python files to create web pages and using Django. I'm just wondering if there is a significant difference between the two. Thanks

+4
source share
4 answers

Django IS plain Python. Thus, the execution time of each such statement or expression will be the same. What you need to understand is that many components come together to offer several advantages when developing for the Internet:

  • Removing common tasks in libraries (auth, data access, templating, routing)
  • Correctness of algorithms (cookies / sessions, cryptography)
  • Reduced user code (due to libraries) that directly affects the number of errors, dev time, etc.
  • The following conventions lead to improved teamwork and code understanding.
  • Plug-in ability; Create or find new function blocks that can be used with minimal integration costs.
  • Documentation and assistance; many people understand the technology and can help (StackOverflow?)

Now, if you have to write your own website from scratch, you will need to implement at least a few components yourself. You will also lose most of the above benefits if you do not spend time developing your site. Django and other web frameworks for every other language are designed to provide common material and allow you to work directly with business requirements.

If you ever deleted the user session code and data access code in PHP before the advent of web frameworks, you won’t even think about the cost of performance associated with the framework, which makes your work interesting and eas (y) ier.

Now, saying that Django comes with a lot of components. It is designed in such a way that most of the time they will not affect you. However, amazing code is executed for each request. If you build a site with Django, and performance just doesn't cut it, you can freely remove all the bits you need. Or you can use the "thin" structure of python.

Indeed, just use Django. This is amazing. It forces many sites millions of times more than anything you (or I) create. There are ways to significantly improve performance, for example, by using caching rather than optimizing the loop over custom middleware.

+10
source

Depends on how your "simple Python" creates web pages. For example, if it uses a template engine, the performance of this engine is of utmost importance. If it uses a database, what level of data access you use (in the context of the requirements for that level), it will make a difference.

So the question arises as to whether your arbitrary (and currently uninstalled) toolkit choices have better run-time performance than those that Django chose. If performance is your primary, primary goal, you should certainly be able to make better choices. However, in terms of total cost - i.e. buying more web servers for slower execution, instead of buying more programmer hours for the “more work for development” option - the question just has too many open elements to attract responsibility.

+4
source

Premature optimization is the root of all evil.

Django makes things extremely convenient if you are doing web development. This plus a great community with hundreds of plugins for common tasks - a real blessing if you are doing serious work.

Even if your raw implementation is faster, I don’t think it will be fast enough to seriously affect your web application. Build it using tools that work at the right level of abstraction, and if performance is a problem, measure it and find out where the bottlenecks are and apply optimization. If after all this you find that the abstractions that Django creates are slowing down your application (which I do not expect them to do), you might consider switching to another structure or writing something manually. You will probably find that you can improve performance by caching, balancing the load across multiple servers and performing “normal tricks” rather than overriding the web frame itself.

+2
source

Django is also plain Python .

See performance mainly depends on the performance of your code.

Most software performance problems are due to inefficient code, and not for choosing tools and language. So implementation matters. AFAIK Django does it superbly and performance is above the mark.

+1
source

Source: https://habr.com/ru/post/1342468/


All Articles