SubSonic Benchmarks

Thursday, March 20th, 2008 at 11:18 pm

I’ve started using an open source project at work called SubSonc. It’s a combination ORM and code generation tool for creating your DAL in .NET. It looks at your database and creates classes with CRUD functions for every table. Out of the box with no configuration. The best part is that they are implemented as partial classes so you can add your own business logic to them very easily. Finally, it doesn’t put the hate on stored procedures - all of them are made available via the generated DAL.

In the past, I had stored procedures for everything. After writing 50 stored procedures I started to worry. I decided to rewrite a small web project to use Subsonic for it’s DAL. I share with you the results in numbers.

Whipping Out the Tape Measure

I started with a small web project that had 80 stored procedures for all CRUD and used SQLDataSources on every ASP.NET page (I know - ew). I used Subsonic 2.1 Beta 2 pretty much out of the box. I used default templates except for a few minor tweaks like adding a static GetInstance function. In the end it was exactly the same functionality as the original website.

Here are the results!

Before Subsonic After Subsonic Difference
Num. Stored Procedures 80 25 31%
Stored Procedures (LOC) 2,859 827 29%
Custom Subsonic Queries (LOC) - 482
aspx.cs (LOC) 2,177 1,794 82%
cs code behind (LOC) 2,729 2,433 89%
Net (LOC) 5,036 3,103 62%
Website Compiled Size (MB) 5.12 8.5 166%

*LOC - Lines of Code

I didn’t include the Subsonic generated code since I’ll never have to touch it.

Whoa! You’ve lost weight!

What happened to 40% of the code? It was most likely basic code not worth writing that Subsonic’s code generation took care of. Also getting rid of SQLDatasource code, and doing databinding in the code behind files. Notice that we kept some stored procedures around. When we’re doing many inner joins - the benefits of using an ORM shrink, and so we used SQL for what it was made for.

The compiled website grew almost twice as big. It’s understandable, but just be aware that there is some overhead.

I think this easily demonstrates the power of SubSonic and why you should be using some sort of tool. The combination of ORM and code generation without GUI tools allows an amazing amount of flexibility and abstraction that somehow is still easy to read and understand. It’s like yoga for your code.

I think it could be interesting to do some benchmark tests to help convince the pointy haired bosses out there.

Please leave a comment