[Technology-related] Performance Analysis of List, Dictionary to Dictionary

Source: Internet
Author: User

1. Background

We often perform copy, conversion, and other operations on the List and Dictionary lists. When the data volume is small (within tens of thousands), the conversion speed is not noticed, but the data volume is large (about one million ), the performance of various conversion methods will be reflected.

This document will test the list conversion efficiency, and finally draw a more efficient method to guide future software development and technology selection. In addition, this article also checks whether exceptions occur when the list data is modified by another thread during list conversion.

Thursday, May 16, 2013

2. Conclusion

1. An exception occurs when the list data is modified by another thread during the conversion from a Dictionary to a Dictionary.

2. The speed of using Dictionary. ToDictionary () is very slow. It takes 1 million milliseconds for 249 Items.

3. The speed of using Dictionary. Value. ToList is very fast, and 1 million pieces of data are only 32 milliseconds;

4. The speed of List. ToDictionary is 109 milliseconds;

3. Environment

1) The Development Environment uses VS2008, C # programs, and you can manually write the code for implementation.

2) The test list contains 1 million pieces of data.

4. Analysis 4.1. Process 1: Modify the list to see if the conversion is abnormal.

1. Method: two threads are used. One thread is responsible for Dictionary conversion and the other is responsible for modifying the list.

Result: The system reports an error.

2. For details, see the source code below)

Use the TH_DicTest0 () thread function to perform the conversion operation, and use the TH_DicTest1 () thread function to modify the list content.

4.2. process 2: List Conversion Speed Analysis

1. Method 1: use the Dictionary. ToDictionary () method,

Result: The [ToDic time] Run Time is 249, and the number of runs is 1.

2. Method 2: Use Dictionary. Value. ToList, and then use List. ToDictionary for conversion;

Result:

1) when using Dictionary. Value. ToList:

16:44:08 logo: [ToList time] Run Time: 32; run times: 1

2) When using List. ToDictionary:

16:44:08 logo: [to Dic time] Run Time: 109; run times: 1

 

Dictionary test MainThread _ tt0 = MainThread _ tt1 = Dictionary <, DataTestItem> _ dicTest = Dictionary <, DataTestItem> Dictionary <, DataTestItem> button17_Click (_ tt0.Add (TH_DicTest0, _ tt1.Add (optional, dataTestItem item = (I =; I <; I ++ item = item. a1 = item. a2 = I + List <DataTestItem> _ lstTest = RunTimeScan. instance (). begin (_ dicTest1 = Dictionary <, DataTestItem> _ lstTest = RunTimeScan. instance (). stop (RunTimeScan. instance (). begin (DataTestItem item RunTimeScan. instance (). stop (RunTimeScan. instance (). begin (_ dicTest1 = _ dicTest. toDictionary (p => p. key, p => RunTimeScan. instance (). stop (AddTipMsg (RunTimeScan. instance (). getRet (AddTipMsg (RunTimeScan. instance (). getRet (AddTipMsg (RunTimeScan. instance (). getRet (AddTipMsg (ex. message + RunTimeScan. instance (). begin (DataTestItem item = (I =; I <; I ++ item = item. a1 = _ dicTest. count () + item. a2 = I + Thread. sleep (RunTimeScan. instance (). stop (AddTipMsg (RunTimeScan. instance (). getRet (AddTipMsg (ex. message +View Code

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.