Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/performance/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Performance 查找特定数据行c的性能_Performance_Linq_C# 4.0 - Fatal编程技术网

Performance 查找特定数据行c的性能

Performance 查找特定数据行c的性能,performance,linq,c#-4.0,Performance,Linq,C# 4.0,各位晚上好, 我正在尝试更新我拥有的数据表中的特定列。 这张桌子大约有500行 我想根据某一列查找行。我一直在读table.select和linq之间的区别,从我读到的内容来看,linq应该快得多 所以我两个都试过了,我放了一个秒表,结果不一样 string time1 = ""; string time2 = "";

各位晚上好,

我正在尝试更新我拥有的数据表中的特定列。 这张桌子大约有500行

我想根据某一列查找行。我一直在读table.select和linq之间的区别,从我读到的内容来看,linq应该快得多

所以我两个都试过了,我放了一个秒表,结果不一样

                                    string time1 = "";
                                string time2 = "";
                                string time3 = "";

                                sw.Start();
                                DataRow foundRowA = datatableTodaysMarkets.Select("BBM_Symbol = '" + newBBM + "'").FirstOrDefault();
                                sw.Stop();
                                time1 = sw.Elapsed.ToString();

                                sw.Reset();
                                sw.Start();
                                DataRow foundRow = datatableTodaysMarkets.Rows.Cast<DataRow>().Where(r => r[0].ToString() == newBBM).FirstOrDefault();
                                sw.Stop();
                                time2 = sw.Elapsed.ToString();

                                sw.Reset();
                                sw.Start();
                                DataRow results = (from myRow in datatableTodaysMarkets.AsEnumerable()

                                              where myRow.Field<string>("BBM_Symbol") == newBBM

                                              select myRow as DataRow).FirstOrDefault();
                                sw.Stop();
                                time3 = sw.Elapsed.ToString();

                                MessageBox.Show(time1 + "\n" + time2 + "\n" + time3);
结果显示在屏幕截图中

我的第一个问题是我知道测试1是一个datatable select语句 测试3是linq。 测试2考虑了什么

另外,这难道不表明测试2比其他选项好得多吗?我可以把这当作福音吗?或者它们是可以改变的许多不同因素


谢谢

test2实际上是linq搜索。而测试3是linq2sql。@JanR Well linq2sql仍然是Linq…是的,但语法略有不同:根据上述测试性能:此测试有一些根本性的错误,主要的错误是测试应该重复多次,最好是数千次,否则结果毫无意义。好的。这确实有帮助。我不知道三者之间的区别,现在我知道test2是直线linq。我还可以尝试运行至少1000个测试。谢谢你的帮助!