[Excerpt] Which of the following is better for the efficiency of repeater and DataGrid ?! Excellent reply

Source: Internet
Author: User
In the past, the repeater was more efficient than the DataGrid, but I don't know if I didn't test it. I was shocked by a test!

I used the stress testing software (ACT) that comes with vs to test the performance of the two, and measured by the number of accessible users per second.

However, the result is beyond my expectation that the DataGrid is more efficient than the repeater!

Let's take a closer look at my testing methods. Are there any problems with my testing methods? If there are no problems, what is the cause of this imagination?


Hardware: CPU: AMD xp2000 +, 80 GB hard disk, MB memory.
Software: Windows 2003 + SP1, vs2003, SQL Server 2000 + SP4

Test data: displays data in a table (city table) with four fields and 349 records.

Objective: To view Data efficiency on a website page. Only test the data display function, regardless of other aspects.


Test conditions:
1. Whether viewstate is enabled
2. 10 records and 349 records are displayed.
3. DataGrid and repeater

In general, the DataGrid is always "accommodating" dozens of people more than the repeater.

Especially when viewstate is disabled.

The DataGrid uses the automatic filling and repeater code.

<Table id = "DG">
<Asp: repeater id = "rpt_test" runat = "server">
<Itemtemplate>
<Tr>
<TD> <% # databinder. eval (container, "dataitem. cityid") %> </TD>
<TD> <% # databinder. eval (container, "dataitem. provinceid") %>
</TD>
<TD> <% # databinder. eval (container, "dataitem. City") %>
</TD>
<TD> <% # databinder. eval (container, "dataitem. aeracode") %>
</TD>
</Tr>
</Itemtemplate>
</ASP: repeater> </table>


Is there any other binding method for repeater?


I often see some articles saying that repeater is better than DataGrid, but what is the result of my test?

We recommend that you perform such a test. I doubt my test results, but I cannot find any reason.

I hope you can study it together.

//////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// ///////////////////

3. Data Binding databinder

General Binding method <% # databinder. eval (container. dataitem, "field name") %> Use databinder. eval to bind data source (dataread or dataset ). The data type Eval will convert the data object into a string. A lot of work has been done in the underlying binding, and reflection performance has been used. This is because it is easy to use, but affects data performance. Let's see <% # databinder. eval (container. dataitem, "field name") %>. When dataset is bound, dataitem is actually a datarowview (if it is bound to a data reader (dataread), it is an idatarecord .) Therefore, directly converting to datarowview will greatly improve the performance.

<% # Ctype (container. dataitem, datarowview). Row ("field name") %>

* We recommend that you use <% # ctype (container. dataitem, datarowview). Row ("field name") %> to bind data. When the data volume is large, the speed can be increased by several hundred times. NOTE 2: 1. Add <% @ import namespace = "system. Data" %>. 2. Note the case sensitivity of the field name ). If it is inconsistent with the query, it may be slower than <% # databinder. eval (container. dataitem, "field name") %> in some cases. To further increase the speed, you can use the <% # ctype (container. dataitem, datarowview). Row (0) %> method. But its readability is not high.

The above is the VB.net method. In C #: <@ % (datarowview) container. dataitem) ["field name"] %>

//////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// ///////////////////

Multi-Data Testing

349 records are displayed on one page. No viewstate is displayed. The datatable is bound to the control, and the DataGrid is bound to the column.

1. DataGrid: Between 50 and 60 RPS.

2. Repeater: <% # databinder. eval (container, "dataitem. cityid") %> method: around 20 RPS.

3. Repeater: <% # (datarowview) container. dataitem) ["cityid"] %> method: around 88 RPS.

4. Repeater: <% # (datarowview) container. dataitem) [0] %> method: About 90 RPS.

//////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// ///////////////////

Dataset and datatable are the same when binding controls. Datatabledefaview view is used. If this name is not used, dataview is used to bind controls.

However, I tested the difference between datareader and datatable.

There is basically no difference in the number of respondents, but datareader will make Asp.net less memory, but the cost is to occupy the database connection for a long time.

Because the bound control occupies a lot of CPU, Asp.net occupies more than 349 of the CPU when 90% records are displayed in the test, while SQL occupies almost no CPU.

If you are using datareader to bind controls, what would you think? The database connection is used, but nothing is done.

//////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// ///////////////////

I. <% # databinder. eval (container, "dataitem. aeracode") %>
The binding speed is indeed a little slower,

3. Repeater: <% # (datarowview) container. dataitem) ["cityid"] %> method: 250 RPS a little more.

4. Repeater: <% # (datarowview) container. dataitem) [0] %> method: 250 RPS a little more.

3, 4 cannot be two methods. One of ASP. NET optimization methods is to bind data.

Ii. In this case, the repeater speed is not much different than the DataGrid speed,
I am also doing a test. When the bound data increases, their respective Influences

//////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// ///////////////////

The landlord conducted an unfair test!

The problem lies in the databinder. Eval method.

You know, databinder. Eval is not used when the DataGrid automatically creates columns.
If the data source of the DataGrid is dataset or datatable,
The DataGrid will automatically find the defaultview of the bound datatable, that is, the dataview object.
Dataview implements the interface: itypedlist
The dataview that implements this interface can tell the DataGrid his architecture information, that is, how many columns he has, what is the name of each column, and even the values of each great power type.

The repeater's databinder. Eval method will find all the attributes of the datatable, and then find out if there are any indexers, indexers, and then try to call the get method of the indexer ...... How can this tedious reflection process be slow?


If your DataGrid uses databinder, I think it will never be faster than repeater.
If repeater is bound with a strong type
(Datarowview) container. dataitem) ["name"]
It shouldn't be slower than the DataGrid ......

Databinder. Eval can only simplify code and adapt data binding expressions to any data source. It is very inefficient in terms of efficiency.

//////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// ///////////////////

You can test whether sqldatareader is used to bind data:

(Idatareader) container. dataitem) ["name"]

What is the problem?



Datareader cannot be disabled during darabind,
Repeater binds datareader as an ienumerable.

The source code of. Net has just been reflected. You should be able to bind it like this:

(Idatarecord) container. dataitem) ["name"]


In fact, write container. dataitem. GetType (). tostring () to know its type.

I didn't expect to copy the value in the enumerator of datareader ......

//////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// ///////////////////

Datareadear is faster than dataset. 15% sqldatareader is faster than oledbdatareader. 50% use datareader's ASP-style table display is faster than datareader bound to the DataGrid. 60% use ordinal's datareader to access fields faster than access by name. true is faster than explicit binding. 24% use cache as much as possible. The above is the comparison test conclusion of ineta Niu Ren Stephen Walther. hope to be useful to everyone

//////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// ///////////////////

If both sides are templates and the values are based on dataitem, the repeater efficiency is unlikely to be low. The templater of repeater is processed as inline HTML. You do not need to create a control and directly use the result of <% # %> as HTML inline. However, the template of the DataGrid is different. The efficiency of creating controls from a table to a row to a cell is actually very low, then, bind the <% # %> value to the properties of the cell control, which is also inefficient.

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.