.NET Compact Framework 2.0 Performance and Reflection
If you spent your time researching performance improvement tips, soon you will find that reflection is a great but expensive feature in terms of performance.
Let's see some metrics, then!
My test environment is just the same as in my previous post
We've got HTC QTEC 9090, VS2005,CF2.0,Sql Ce 3.0.
I used the same database structure and 10000 rows to fetch. Every scenario makes 5 subsequent runs. Application is restarted before each test scenario run. Scenario 1 is not listed here , because it uses DataRow instances to represent database table rows.
The code is almost the same. I changed only the way the BObject instance is created. It is created by using Activator.CreateInstance method, this time.
List<BObject> boList = new List<BObject>(); ... IDataReader reader = cmd.ExecuteReader(); ... while(reader.Read()) { //This was the old instance creation //BObject bo = new BObject(); //This is the new extra time-consuming instance creation BObject bo = (BObject)Activator.CreateInstance(typeof(BObject)); bo.id = reader.GetInt32(0); bo.data1 = reader.GetString(1); bo.data2 = reader.GetDateTime(2); bo.data3 = reader.GetDouble(3); boList.Add(bo); } |
I repeated the same testing scenarios and here come results:
Scenario 2: SqlCeDataReader | |||
# | Time[ms] | Memory[bytes] | Time increase[%] |
1 | 10064 | 962216 | 99 |
2 | 8344 | 1125212 | 142 |
3 | 8261 | 1295408 | 136 |
4 | 8288 | 1422712 | 143 |
5 | 8333 | 952280 | 129 |
Scenario 3-a:SqlCeResultSet,None | |||
# | Time[ms] | Memory[bytes] | Time increase[%] |
1 | 10576 | 962064 | 97 |
2 | 9091 | 1125200 | 133 |
3 | 9029 | 1295396 | 131 |
4 | 9062 | 1422700 | 129 |
5 | 9019 | 952128 | 133 |
Scenario 3-b:SqlCeResultSet,Insensitive | |||
# | Time[ms] | Memory[bytes] | Time increase[%] |
1 | 15486 | 9962064 | 27 |
2 | 14016 | 1125200 | 29 |
3 | 13886 | 1295396 | 28 |
4 | 14118 | 1422700 | 29 |
5 | 14105 | 952128 | 30 |
Scenario 3-c:SqlCeResultSet,Scrollable,Updatable,Sensitive | |||
# | Time[ms] | Memory[bytes] | Time increase[%] |
1 | 14054 | 962064 | 42 |
2 | 12494 | 1125200 | 70 |
3 | 12369 | 1295396 | 64 |
4 | 12471 | 1422700 | 65 |
5 | 12406 | 952128 | 67 |
We've got ~25-140 percents time increasing, due to using this resource hungry feature! There is also a small memory overhead. It is not as meaningful as the time increase. However the memory increase was stable across all the test scenario runs, that I've performed. It is interesting that testing scenarios 2 and 3-a(the faster data access methods) report far greater time increasing compared with the rest ones. The time diff. between scenario 3-a and 3-b in the previous test cases had a mean value of ~60%. In this case the diff. is only ~30% due to performance loss in scenario 3-a.
One of the reasons, which motivated me to perform these tests was that Activator.CreateInstance pattern is very useful, when extendability and flexibility are required.
And while this pattern is frequently used in the desktop environment, it comes with a great cost in the CF world.
No comments:
Post a Comment