You perform benchmark tests for a method like BulkInsert, but you get very bad performance results.
The performance issue may be caused by some common mistakes:
- Forget to JIT compile the library
- Include method not related to the test
Forget to JIT compile the library
In C#, the code is compiled into IL by the compiler. Then when needed, the IL is compiled just-in-time (JIT) into the native assembly language of the host machine.
Additionally, some libraries like Entity Framework require some extra work like creating/reading the model. Some people report the first load taking several seconds
Invoke the method once before performing the benchmark tests
Someone once reported a performance issue and thought our BulkInsert method was slow. We discovered he was including the time to Add every entity to the context.
The Add method was taking 99,9% of the total time while BulkInsert only 0,1%.
The Add method doesn’t affect much the performance when adding 100 entities, but if you make your test with 10,000 entities:
- Add: 99.6%
- BulkInsert: 0,4%!
Include only the method you want to benchmark.
Here is an example of how we normally do all our benchmarks tests