c# - Performance wise difference between returning direct initialization and storing in variable -
is there difference (performance wise) between:
public user getuser1() { var user = _database.user.first(); return user; } public user getuser2() return _database.user.first(); }
here output linqpad c# 7.0 same functions on database:
getuser1: il_0000: ldarg.0 il_0001: call linqpad.user.typeddatacontext.get_users il_0006: call system.linq.queryable.first<user> il_000b: ret getuser2: il_0000: ldarg.0 il_0001: call linqpad.user.typeddatacontext.get_users il_0006: call system.linq.queryable.first<user> il_000b: ret
here output optimization turned off. note nop
s , br.s
debugging/breakpoint purposes.
getuser1: il_0000: nop il_0001: ldarg.0 il_0002: call linqpad.user.typeddatacontext.get_users il_0007: call system.linq.queryable.first<user> il_000c: stloc.0 // user il_000d: ldloc.0 // user il_000e: stloc.1 il_000f: br.s il_0011 il_0011: ldloc.1 il_0012: ret getuser2: il_0000: nop il_0001: ldarg.0 il_0002: call linqpad.user.typeddatacontext.get_users il_0007: call system.linq.queryable.first<user> il_000c: stloc.0 il_000d: br.s il_000f il_000f: ldloc.0 il_0010: ret
Comments
Post a Comment