Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is ORM slow? Does it matter? [closed]

Tags:

I really like ORM as compared to store procedure, but one thing that I afraid is that ORM could be slow, because of layers and layers of abstraction. Will using ORM slow down my application? Or does it matter?

like image 504
Graviton Avatar asked Mar 31 '09 02:03

Graviton


People also ask

Why is ORM slow?

Long story short: for anything but the most basic of queries, ORMs require multiple queries to fetch all the data you need. This, more than anything else, is why ORMs are perceptually slower than raw SQL. Most existing benchmarks use flat CRUD queries that are too simplistic to capture this unfortunate characteristic.

When should you avoid ORM?

If you know your data access pattern is going to be complex or you plan to use a lot of database-specific features, you may not want to use an ORM.

Is ORM faster than SQL?

There is little research on which technique is faster. Intuitively, Raw SQL should be faster than Eloquent ORM, but exactly how much faster needs to be researched. In particular, when one uses Raw SQL over Eloquent ORM, one makes a trade-off between ease of development, and performance.

Does ORM improve performance?

An ORM can provide many benefits to development speed, code readability and can remove a lot of code repetition. I would recommend using one if it will make your application easier to develop.


1 Answers

Yes, it matters. It is using more CPU cycles and consequently slowing your application down. Hear me out though...

But, consider this: what is more expensive? Server hardware or another programmer? Server hardware, generally, is cheaper than hiring another team of programmers. So, while ORM may be costing you CPU cycles, you need one less programmer to manage your SQL queries, often resulting in a lower net cost.

To determine if it's worth it for you, calculate or determine how many hours you saved by using an ORM. Then, figure out how much money you spent on the server to support ORM. Multiply the hours you saved by your hourly rate and compare to the server cost.

Of course, whether an ORM actually saves you time is a whole another debate...

like image 138
carl Avatar answered Oct 12 '22 07:10

carl