Many people wonder how many lines of code they really save thanks to PostSharp beyond the buzz and marketing promises. Thanks to data collected through our CEIP program, we are able to shed some light on this question.

When you opt-in for CEIP, we collect a few anonymous metrics for all projects you build. Two of these metrics are interesting here: the number of lines of code (we just count instructions, not declarations like fields, properties, type headers or method headers), and the number of aspect instances in your code.

We feed this data into a database that already has a few GBs. Let’s use R to analyze it.

First, we load the data. We filter out demo or test projects with fewer than 100 lines.

db <- odbcConnect("Feedback")
m <- sqlQuery( db, "SELECT InputLines, AspectsInstances 
FROM MetricSample s TABLESAMPLE ( 25 percent )
WHERE AspectsInstances > 0 and InputLines > 100")

We want to know how many aspects per line manual of code we have. The invert metric is easier to represent and interpret, so let’s compute it:

hist( m$InputLines / m$AspectsInstances, xlim=c(0,200), breaks=200000, col="lightblue"  )

Here is the result of this graph:

And here are the summary of this vector:

summary(m$InputLines / m$AspectsInstances)
# Min.  1st Qu.   Median     Mean  3rd Qu.     Max. 
# 0.0     12.6     43.8    626.8    199.0 357800.0 

What does it mean?

25% of PostSharp-enabled projects have an aspect every 13th line of code or less. 50% of these projects have an aspect every 44th line of code.

Suppose that each aspect avoids 4 lines of code. This is a pretty pessimistic estimate – an INotifyPropertyChanged aspect can save dozens of lines of code per instance. Also, PostSharp counts a line of code as any location where the debugger can stop, so it usually counts more than lines of text. So, with this ballpark estimate of how much a single aspect instances saves, we can say that:

  • 25% of projects would be 30% larger without PostSharp, i.e. PostSharp saves 23% of development costs.
  • For 50% of projects, the codebase increase without PostSharp would be 9% and the teams saves 8% with PostSharp.

Note that large projects are overrepresented in our sample because CEIP data are uploaded by many team members. However, this bias also reflects the higher economic importance of large projects.

Teams who use PostSharp the best get a 23% cost reduction.

This is pretty amazing in my eyes and I’m proud of us.

Happy PostSharping!


Pingbacks and trackbacks (1)+

Comments are closed