Datarow indexing performance (integer vs. String)

Source: Internet
Author: User

Source: http://www.codeproject.com/KB/database/datarow_indexing.aspx

Article:

Introduction Background

When I was developing an application for Pocket PC that used quite large dataset, I wondered where I coshould gain at least some bits of performance. I was filling some data to a tree view control, storing some data else, doing selects from datatable and getting the data from columns of datarows. as you know, you can access the datarow's columns by using either string indexing (dataRow["NAME"]Or integer IndexingdataRow[3]).

I thought I cocould test performance of both indexers-I just wanted to know if I cocould still use string indexers (they are more comfortable to work) -Or to rework the code of this app to use integer indexing. so here comes the performance tester.

The Code

The approach to solve this problem was to create large enough database (datatable in my case), then in loops traverse the rows, and test the indexing itself. this is done by passing it as a parameter to a dummy function: dummy(dataRow["STR1"]));.

The datatable's structure is as follows:

The columns are named by their data types, so str1 is a string, int1 an integer, date1 the datetime etc.

The program first generates user-entered number of rows, then n-times does integer indexing test and string indexing test. the indexing test m-Times gets each row in table and calldummy function on each column of that row.

There is a measuring-How long does it take to do the integer indexing test and the string indexing test.

In the end, the application writes out how much did take integer and string Indexing in total, and each one in average.

Example:

int indexingtotal: 42171,875 mseach: 421,71875 msstring indexingtotal: 149312,5 mseach: 1493,125 ms 
Conclusion

According to the tests on my machine (Intel core2 duo 1, 86 GHz, 1 gb ram) the integer indexing is approximately 3.5-4 times faster than the string indexing (results vary according to row count and repetition count ).

Clearly, integer indexing is faster, but when we take in account that both indexers take a very short time (about 1 µs) to access a column, the difference is noticeable only when applied on large amounts of data.

 

I will translate this article. While datacolumn is not contained. So add datacolumn test.

 

Result:

How many rows in testing datatable? 100000
How many times to process all rows in one loop? 100
How many times to repeat int/string indexing? 10
Generating data...
------------------------ 0 ---------------------------
1. Int indexing: 23583.912 Ms
2. String indexing: 39206.376 MS
3. datacolumn indexing: 20148.9728 Ms
------------------------ 1 ---------------------------
1. Int indexing: 22842.8464 Ms
2. String indexing: 38715.6704 MS
3. datacolumn indexing: 20599.6208 Ms
------------------------ 2 ---------------------------
1. Int indexing: 23393.6384 Ms
2. String indexing: 39586.9232 MS
3. datacolumn indexing: 21080.312 Ms
------------------------ 3 ---------------------------
1. Int indexing: 21540.9744 Ms
2. String indexing: 36011.7824 MS
3. datacolumn indexing: 19918.6416 Ms
------------------------ 4 ---------------------------
1. Int indexing: 24665.4672 Ms
2. String indexing: 36642.6896 MS
3. datacolumn indexing: 18947.2448 Ms
------------------------ 5 ---------------------------
1. Int indexing: 21110.3552 Ms
2. String indexing: 38275.0368 MS
3. datacolumn indexing: 20479.448 Ms
------------------------ 6 ---------------------------
1. Int indexing: 22332.112 Ms
2. String indexing: 39476.7648 MS
3. datacolumn indexing: 20329.232 Ms
------------------------ 7 ---------------------------
1. Int indexing: 23964.4592 Ms
2. String indexing: 38885.9152 MS
3. datacolumn indexing: 21671.1616 Ms
------------------------ 8 ---------------------------
1. Int indexing: 23163.3072 Ms
2. String indexing: 39877.3408 MS
3. datacolumn indexing: 21140.3984 Ms
------------------------ 9 ---------------------------
1. Int indexing: 22862.8752 Ms
2. String indexing: 39636.9952 MS
3. datacolumn indexing: 21230.528 Ms
######################################## #############
1 # int Indexing
Total: 229459.9472 MS
Each: 22945.99472 MS
2 # string Indexing
Total: 386315.4944 MS
Each: 38631.54944 MS
3 # datacolumn Indexing
Total: 205545.56 MS
Each: 20554.556 MS

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.