0

I'm playing around with DataVirtualization and Async. What are some options I have for quantifying load times of a ListBox that I'm binding my virtualized data collections to?

I need a way to compare the virtualized vs non-virtualized data loading. Have been unsuccessful in locating any resources for this topic.

Should I just put a stopwatch on the ListBox_Loaded event in the code behind?

Thanks in advance!

Rachael
  • 1,965
  • 4
  • 29
  • 55
  • I fail to understand what does `ListBox` have to do with your DATA load times. BTW this question is unclear. – Federico Berasategui Sep 05 '13 at 01:35
  • 1
    The only part I understood was he wishes to compare loading time between virtualized and non-virtualized ListBox. I suggest you to start your StopWatch on event ListBox.Initalized. And to stop your StopWatch on event ListBox.Loaded. – ninja hedgehog Sep 05 '13 at 07:55
  • I meant the data loaded BY the `ListBox`, which is being loaded in "pages." Or in the cases where I am not virtualizing any data, I need to know how long it takes to load data into the `ListBox` when it makes its only call to the database. – Rachael Sep 05 '13 at 16:12
  • Actually, it's stated specifically in the question that I'm trying to find "load times *of a listbox* that I'm binding my virtualized collections to." – Rachael Sep 05 '13 at 16:14
  • The point here is to capture how long it takes to populate my ListBox given different loading scenarios...I have a lot of data to display (/page through) so this very much slows down ListBox performance. – Rachael Sep 05 '13 at 16:17

1 Answers1

0

You can use a System.Diagnostics.Stopwatch for this. Make sure that you start it before you set the ListBox.ItemsSource property and stop it as you said, in the ListBox.Loaded event:

In XAML:

<ListBox Name="ListBox" />

In code constructor:

public MainWindow()
{
    InitializeComponent();
    ListBox.Loaded += new RoutedEventHandler(ListBox_Loaded);
    Items.AddRange(Enumerable.Range(1, 100000000));
    stopwatch = new Stopwatch();
    stopwatch.Start();
    ListBox.ItemsSource = Items;
}

Add the handler with a break point after the call to stop the Stopwatch:

private void ListBox_Loaded(object sender, RoutedEventArgs e)
{
    stopwatch.Stop();
    TimeSpan elapsedTime = stopwatch.Elapsed;
}

However, unless you have millions of rows of data, or extremely complicated DataTemplates, you may not see much differences. In this simple example, these 100,000,000 numbers are processed in well under one second. Even when I added a larger DataTemplate for the integers, it still rendered them all in just over one second. Furthermore, repeatedly running this scenario will return differing results, so this is somewhat unreliable as well.

Sheridan
  • 68,826
  • 24
  • 143
  • 183
  • Hmm, well thanks for this post. This got me what I needed to know for now. I am using DataTemplates and have millions of rows of data. I can see that Entity Framework 5 is very quick to "cache" my queries, but the `ListBox` takes a very long time (several seconds for around 5,000) to "reload" the collections bound to my queries. – Rachael Sep 05 '13 at 16:48
  • @Rach, as an experiment, temporarily remove the `DataTemplate` so that your items are rendered simply as strings and take another time measurement... maybe your `DataTemplate` can be taking too much time to render. You could consider simplifying it a bit to save time maybe? – Sheridan Sep 06 '13 at 08:04
  • I actually did try this, with some noticeable improvement. Unfortunately, the `DataTemplate` is pretty simple to begin with and I do need it. I think with the DataVirtualization article I found [here](http://www.zagstudio.com/blog/498#.Uio8ODZQHAQ) and some EntityFramework improvements (reducing the number of items attached to the object graph) I should be able to improve virtualized "paging" of my data. – Rachael Sep 06 '13 at 20:36