For fun, I thought I'd try a little test.
I thought:
We know that C# gets converted to MSIL, so it makes sense that the
more code there is, the more MSIL there would be and therefore the
slower the load.
But, it turns out this is not the case.
I tried dynamically loading 2 dll's:
- One was nearly empty,
- The other had 100,000+ lines of code in.
Sample code below:
private void LoadTest()
{
// Startup test just in case the loader needs priming....
var dll0 = Assembly.LoadFile(@"C:\Users\me\Documents\visual studio 2015\Projects\DeleteMeApp\DeleteMe0\bin\Debug\DeleteMe0.dll");
Stopwatch st = new Stopwatch();
st.Start();
// This dll is nearly empty
var dll1 = Assembly.LoadFile(@"C:\Users\me\Documents\visual studio 2015\Projects\DeleteMeLib1\bin\Debug\DeleteMeLib1.dll");
st.Stop();
var time1 = st.ElapsedMilliseconds;
Stopwatch st2 = new Stopwatch();
st2.Start();
// This dll has over 100,000 lines of code in
var dll2 = Assembly.LoadFile(@"C:\Users\me\Documents\visual studio 2015\Projects\DeleteMeApp\DeleteMeLib2\bin\Debug\DeleteMeLib2.dll");
st2.Stop();
var time2 = st.ElapsedMilliseconds;
}
Results
- Run 1: Both 16ms
- Run 2: Both 25ms
- Run 3: Both 18ms
I didn't quite understand the results. I thought maybe the compiler was being extra clever and my 100,000+ lines of code was somehow being compiled to nothing.
So, I followed this post to view the MSIL and the large file had significantly more MSIL code than the small file.
Next Test
Still in disbelief, i added 100,000 different public void
methods to the 100,000+ lines of code and re-ran the test.
- Run 1: Both 11ms
- Run 2: Both 9ms
- Run 3: Both 10ms
ildasm.exe became unresponsive, so I'm guessing the IL was pretty big.
Conclusion
No; it seems the number of lines of code do not relate to the load time.