我需要阅读包含44-50个表的数据库,总共大约有500万个条目(每个表大约有100 k个条目)。
这些数据包括运动中的位置跟踪数据(运动员、裁判和球)和比赛项目(投篮、比赛、铲球、.):
比赛项目在性能上可以忽略不计。
桌子: PlayerXYZ或Ball
现在,读取数据库并将内容分配给DataTable字典需要86秒钟。那是每秒57000个条目的“速度”。
private async void ProcessLoadMatch()
{
var window = Application.Current.MainWindow as MetroWindow;
var controller = await window.ShowProgressAsync("Please wait...", "Process message", false, new MetroDialogSettings());
controller.SetTitle("Loading Match-Data...");
await Task.Run(() => HandleLoadMatch(controller));
await controller.CloseAsync();
}
static bool HandleLoadMatch(ProgressDialogController ProgCtrl)
{
string DataBasePath = @"W:\data\sqlite";
string DataBaseName = "db";
string dbpath = @DataBasePath + @"\" + @DataBaseName + ".sqlite";
SQLiteConnection con = new SQLiteConnection("Data Source=" + dbpath + ";Version=3;");
con.Open();
DataTable tables = con.GetSchema("Tables");
double currentTable = 0;
double Percentage = 0;
foreach (DataRow row in tables.Rows)
{
currentTable++;
Percentage = (100 / tables.Rows.Count) * currentTable;
string tablename = (string)row[2];
ProgCtrl.SetMessage("Loading Data\nCurrent Table ("+currentTable+" of "+tables.Rows.Count+"): " + tablename + " ...");
ProgCtrl.SetProgress(Percentage / 100);
string CmdString = "SELECT * FROM " + tablename;
SQLiteCommand cmd = new SQLiteCommand(CmdString, con);
SQLiteDataAdapter sda = new SQLiteDataAdapter(cmd);
DataTable MatchDt = new DataTable();
sda.Fill(MatchDt);
CurrentDataSet.CurrentMatch.Data.Add(tablename, MatchDt);
}
con.Close();
return true;
}CurrentDataSet.CurrentMatch.Data:
class CurrentMatch
{
public static Dictionary<string, DataTable> Data = new Dictionary<string, DataTable>();
}我的系统:
我的代码中是否还有任何性能潜力?我定期加载不同的数据库,因此如果有显著的性能提高,我们将不胜感激。
发布于 2016-10-31 12:29:02
只是一些想法..。
return true是不必要的。无论如何,该方法都不会返回false。最好是void。发布于 2016-11-07 22:04:53
你的方法很简单。从所有表加载所有记录。它基本上意味着加载整个数据库。为了获得更好的表现,问问自己:
如果答案是否定的,请考虑另一种方法:
您还可以尝试使用内存中数据库方法。
https://codereview.stackexchange.com/questions/116472
复制相似问题