SQLite插入1000行数据居然耗时9秒。。

shsyzl007 shsyzl007 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
以下为代码
  static void Main(string[] args)
{
string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
SQLiteConnection connection = new SQLiteConnection("Data Source=" + directoryName + @"\Test.db");
connection.Open();

SQLiteCommand commandClearDB = new SQLiteCommand("delete FROM highscores", connection);
commandClearDB.ExecuteNonQuery();

DateTime now = DateTime.Now;
for (int i = 0; i < 1000; i++)
{
SQLiteCommand command = new SQLiteCommand("insert into highscores (name, score) values ('Me', 3000)", connection);
command.ExecuteNonQuery();
}

SQLiteCommand commandCount = new SQLiteCommand("select count(*) from highscores", connection);
object count = commandCount.ExecuteScalar();

string tip = ((DateTime.Now - now)).TotalMilliseconds.ToString();
Console.WriteLine(tip);
Console.WriteLine("数据行:" + count);
Console.ReadKey();
}

...全文

相关推荐

评论 3
收藏 已收藏
分享
返回顶部
shsyzl007
其他数据库 2,208 成员 9,519 内容