using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
namespace TestPerformance
{
public partial class TestListViewPerformance : Form,ITest
{
const string TXT_NOT_USED_UPDATE = "Not call Update mehthod : {0}";
const string TXT_USED_UPDATE = "Call Update mehthod : {0}";
public TestListViewPerformance()
{
InitializeComponent();
}
/// <summary>
/// ListViewItem을 추가합니다.
/// </summary>
/// <param name="isUseUpdateMethod">BeginUpdate, EndUpdate 호출 여부</param>
/// <param name="lvis">ListViewItem 배열</param>
private void AddListViewItem(bool isUseUpdateMethod, ListViewItem[] lvis)
{
if (isUseUpdateMethod)
{
this.lv_test.BeginUpdate();
}
foreach (var item in lvis)
{
this.lv_test.Items.Add(item);
}
// AddRange는 내부적으로 BeginUpdate와 EndUpdate를 호출하는 것 같습니다.
//this.lv_test.Items.AddRange(lvis);
if (isUseUpdateMethod)
{
this.lv_test.EndUpdate();
}
}
/// <summary>
/// BeginUpdate, EndUpdate를 사용하지 않는 로직을 수행합니다.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_notUseUpdate_Click(object sender, EventArgs e)
{
Stopwatch sw = new Stopwatch();
this.lv_test.Items.Clear();
sw.Start();
this.AddListViewItem(false, this.CreateTestListViewItems());
sw.Stop();
Console.WriteLine(string.Format(TXT_NOT_USED_UPDATE,sw.Elapsed.ToString()));
Debug.WriteLine(string.Format(TXT_NOT_USED_UPDATE, sw.Elapsed.ToString()));
}
/// <summary>
/// BeginUpdate, EndUpdate를 사용하는 로직을 수행합니다.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_useUpdate_Click(object sender, EventArgs e)
{
Stopwatch sw = new Stopwatch();
this.lv_test.Items.Clear();
sw.Start();
this.AddListViewItem(true, this.CreateTestListViewItems());
sw.Stop();
Console.WriteLine(string.Format(TXT_USED_UPDATE, sw.Elapsed.ToString()));
Debug.WriteLine(string.Format(TXT_USED_UPDATE, sw.Elapsed.ToString()));
}
/// <summary>
/// Test ListViewItem을 생성합니다.
/// </summary>
/// <returns></returns>
private ListViewItem[] CreateTestListViewItems()
{
ListViewItem[] lvis = new ListViewItem[500];
for (int i = 0; i < lvis.Length; i++)
{
lvis[i] = new ListViewItem(i.ToString());
for (int j = 1; j < this.lv_test.Columns.Count; j++)
{
lvis[i].SubItems.Add(i.ToString());
}
}
return lvis;
}
public void StartTest()
{
throw new NotImplementedException();
}
}
}
|