c# - Dapper/EF - why is there a performance increase when variable is outside of using -


i ran both below queries using same params , stored proc. example takes on minute, whereas example b takes under 20 seconds. if call same proc using ef, i'm down 10 seconds (there on 50000 records returned). it's puzzling why ef quicker.

example a:

            list<resultobj> result;              using (var conn = new sqlconnection(configurationmanager.connectionstrings["string"].connectionstring))             {                     result = conn.query<resultobj>("spproc", param: new { /*params here*/ },                      commandtype: commandtype.storedprocedure, commandtimeout: 300).tolist();             } 

example b:

            using (var conn = new sqlconnection(configurationmanager.connectionstrings["string"].connectionstring))             {                 var result = conn.query<resultobj>("spproc", param: new { /*params here*/ },                      commandtype: commandtype.storedprocedure, commandtimeout: 300).tolist();             } 

why moving result variable out of using's scope lead such large increase in performance?

there no reason case. in case, suspect difference due database server bottlenecks - perhaps primed data memory first time (the slow one, had hit disk) - or perhaps server contention or network throughput issues. describe in 2 examples can caused underlying data source - not difference between variable declared.

as minor note: aslist() preferable tolist(), too: save tiny sliver of time (probably less millisecond).

when profiling, should:

  • work in release mode without ide attached
  • perform jit , prime external sources first, executing things @ least once before start timing
  • measure multiple times (in case of fast operations, doing thousands of times obtain average common - not applicable if takes 30s per iteration, obviously)
  • force gc etc ahead of time additional gc solely fault of thing being tested
  • try avoid competing acrivity on test machine / server / network

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -