Print Page | Close Window

Asynchronous Performance Question

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2320
Printed Date: 05-Feb-2026 at 1:35am


Topic: Asynchronous Performance Question
Posted By: BillG
Subject: Asynchronous Performance Question
Date Posted: 19-Nov-2010 at 10:07am
Is there any difference, performance wise between using lambda expressions to perform the callback in the Get data method versus an actual callback method being used?
 
Bill
 



Replies:
Posted By: DenisK
Date Posted: 19-Nov-2010 at 5:23pm
Hi Bill;

I used the following code to time it out.

public void TimingLambdaExpressionVsCallback() {

      _lambdaStopwatch.Start();
      var lambdaQuery = _mgr.Employees;
      lambdaQuery.ExecuteAsync(e => {
        var employees1 = new ObservableCollection<Employee>();
        e.Results.ForEach(employees1.Add);
        _lambdaStopwatch.Stop();
        Output += "_lambdaStopwatch = " + _lambdaStopwatch.ElapsedMilliseconds + Environment.NewLine;
      });

      _callbackStopwatch.Start();
      var callbackQuery = _mgr.Employees.ExecuteAsync();
      callbackQuery.Completed += callbackQuery_Completed;
    }

    void callbackQuery_Completed(object sender, EntityQueriedEventArgs<Employee> e) {
      var employees2 = new ObservableCollection<Employee>();
      e.Results.ForEach(employees2.Add);
      _callbackStopwatch.Stop();
      Output += "_callbackStopwatch = " + _callbackStopwatch.ElapsedMilliseconds + Environment.NewLine;
    }

_lambdaStopwatch would take between 3ms and 23ms longer than _callbackStopwatch.



Print Page | Close Window