执行时间不同 CListCtrl::InsertItem 在相同数量的记录上
Different time of the execution CListCtrl::InsertItem on the same amount of records
我有一个包含 10000 条记录的 CListCtrl,当程序启动时,此操作的时间是 ~1.3 秒。但是,如果用户刷新列表,它将在 ~2.5 - 3 秒内填满。
在这两种情况下,使用相同的代码段:
SetRedraw(FALSE);
SetItemCount(nCount);
// insert
SetRedraw(TRUE);
变量 nCount 在程序启动时等于 0,当用户刷新列表时等于 10000。
为什么填写清单的时间如此不同?
UPD:最少的代码
void CTestList::Init()
{
InsertColumn(0, _T("Number"), 0, 50);
InsertColumn(1, _T("Obj name"), 0, 150);
InsertColumn(2, _T("Creator"), 0, 100);
InsertColumn(3, _T("Editor"), 0, 100);
}
void CTestList::Reset()
{
LVITEM item;
item.iItem = 0;
for (int i = 0; i < 10000; i++)
{
InsertRow(item, i);
item.iItem++;
}
}
void CTestList::InsertRow(LVITEM& item, int num)
{
CString strNum;
//
item.iSubItem = 0;
item.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;
item.lParam = NULL;
item.iImage = 0;
strNum.Format(_T("%d"), num);
item.pszText = (LPTSTR)(LPCTSTR)strNum;
InsertItem(&item);
//
item.mask = LVIF_TEXT;
item.iSubItem = 1;
item.pszText = _T("Test object");
SetItem(&item);
//
item.mask = LVIF_TEXT;
item.iSubItem = 2;
item.pszText = _T("Any one");
SetItem(&item);
//
item.iSubItem = 3;
item.pszText = _T("Another one");
SetItem(&item);
}
void CApp::FillList()
{
CWaitCursor wait;
m_list.DeleteAllItems();
clock_t begin = clock();
m_list.SetRedraw(FALSE);
m_list.SetItemCount(nCount);
m_list.Reset();
m_list.SetRedraw(TRUE);
clock_t end = clock();
double dif = static_cast<double>(end - begin) / CLOCKS_PER_SEC;
CString str;
str.Format(_T("Insertion time: %f"), dif);
AfxMessageBox(str);
}
我已经在我的机器上测试了你的代码。仅当我在调试器中运行程序(使用 F5)时,我才能重现不同的计时,但如果在没有调试器的情况下运行它(使用 Ctrl+F5),则不能重现。因此,这似乎与您的代码或Windows API没有直接关系,而是与调试器有关。
相关文章:
- 将两个数组中的差异记录在第三个数组中
- 禁止在控制台上记录谷神星
- 创建 Spdlog 异步文件记录器时遇到困难
- fastrtps:如何在发布/订阅级别使用 DDS 历史记录?
- 如何将自定义记录器与websocketpp一起使用?
- C++结构到德尔福记录dll调用
- 如何判断SSL_read是否已经接收并处理了来自单个消息的所有记录
- 如何实现具有多个平台__FILE__和__LINE__信息的 C/C++ 可变参数日志记录宏?
- 我是否可以使用 win32 句柄以编程方式记录发送到/接收到 USB/COM 的内容
- 使用 Doxygen 记录枚举类值,而不启用EXTRACT_ALL
- 在C++中隐藏键盘记录器的控制台窗口
- 堆栈上的最大激活记录数
- 记录Doxygen中的命名
- 为什么Qt Creator的应用程序输出不能从spdlog记录器打印
- 在SQLITE数据库中写入记录需要花费大量时间.如何提高刀片操作效率?
- Qt 错误:QSqlQuery::value:尝试从表中检索统计信息时未定位在有效记录上 (QComboBox)
- 麻烦得到提升::记录器编译
- C++ 中混合二进制/文本日志记录的最佳做法
- 修改链表中的记录C++
- 执行时间不同 CListCtrl::InsertItem 在相同数量的记录上