-
Notifications
You must be signed in to change notification settings - Fork 0
Home
This project demonstrates Benchmark .NET.
A benchmark is a measurement or set of measurements relating to the execution of some code. Benchmarks allow you to compare the relative performance of code as you begin making efforts to improve performance.
The process being benchmarked involves organisation records in a csv file being read and then saved to a database.
The process reads records from 1 or more csv files and then saves them to a database table in batches.
The number of files and number of records saved in a batch can be changed to test different quantities of data and optimising the saving process.
Three different loops are benchmarked.
-
Standard for loop - for (int i = 0; i < files.Count; i++)
-
Parallel for loop - Parallel.ForEach
-
Parallel for async loop - Parallel.ForEachAsync
Method | Mean | Error |
---|---|---|
ForLoop | 116.68 s | NA |
ParallelForLoop | 40.12 s | NA |
ParallelForLoopAsync | 52.17 s | NA |
Method | Mean | Error |
---|---|---|
ForLoop | 17.73 s | NA |
ParallelForLoop | 10.25 s | NA |
ParallelForLoopAsync | 10.91 s | NA |
Method | Mean | Error |
---|---|---|
ForLoop | 15.338 s | NA |
ParallelForLoop** | 9.831 s | NA |
ParallelForLoopAsync | 10.785 s | NA |
Method | Mean | Error |
---|---|---|
ForLoop | 15.39 s | NA |
ParallelForLoop | 10.39 s | NA |
ParallelForLoopAsync | 10.34 s | NA |
Method | Mean | Error |
---|---|---|
ForLoop | 15.76 s | NA |
ParallelForLoop | 12.29 s | NA |
ParallelForLoopAsync | 10.94 s | NA |
Method | Mean | Error |
---|---|---|
ForLoop | 126.33 s | NA |
ParallelForLoop | 104.19 s | NA |
ParallelForLoopAsync*** | 79.09 s | NA |
**When processing 10 files x 10000 records the optimal process is to use the Parallel.ForEach loop and save 250 records at a time.
***When processing 100 files x 10000 records the optimal process is to use the Parallel.ForEachAsync loop and save 250 records at a time.