先构造一个DataTable:
public DataTable GetDataTable()
{
DataTable dtTmp = new DataTable();
dtTmp.Columns.Add("", typeof(string));
dtTmp.Columns.Add("", typeof(string));
dtTmp.Columns.Add("", typeof(string));
dtTmp.Columns.Add("", typeof(string));
dtTmp.Columns.Add("", typeof(string));
dtTmp.Columns.Add("", typeof(string));
dtTmp.Columns.Add("", typeof(string));
dtTmp.Columns.Add("", typeof(string)); for (int i = ; i < ; i++)
{
DataRow dr = dtTmp.NewRow(); dr[""] = "数据" + i;
dr[""] = "数据" + i;
dr[""] = "数据" + i;
dr[""] = "数据" + i;
dr[""] = "数据" + i;
dr[""] = "数据" + i;
dr[""] = "数据" + i;
dr[""] = "数据" + i; dtTmp.Rows.Add(dr);
} return dtTmp;
}
建立单元测试项目:
[TestClass]
public class UnitTest1
{
Class1 cs1;
DataTable dt;
public UnitTest1()
{
cs1 = new Class1();
dt = cs1.GetDataTable();
} [TestMethod]
public void TestMethod0()
{
/*空测试项目*/
} [TestMethod]
public void TestMethod1()
{
DataTable dtt = dt.AsEnumerable().Where(o => o.Field<string>("").Contains("")).AsDataView().ToTable();
} [TestMethod]
public void TestMethod2()
{
DataTable dtt = (from a in dt.AsEnumerable() where a.Field<string>("").Contains("") select a).AsDataView().ToTable();
} [TestMethod]
public void TestMethod3()
{
dt.AsDataView().RowFilter = "[1] like '%0%'";
DataTable dtt = dt;
} [TestMethod]
public void TestMethod4()
{
DataTable dtt = dt.Select("[1] like '%" + "" + "%'").CopyToDataTable();
}
}
运行后看效率:
1000行数据量:
10000行数据量:
100000行数据量:
1000000行数据量:
DataTable无索引状态下测试,也是日常最常用的数据过滤方法之一,
再大就不测了,数据量太大放DataTable本来就不适合,可以考虑nosql了,效率吗,如上,仅供参考,欢迎拍砖.