Development With A Dot

Blog on development in general, and specifically on .NET

Sponsors

News

My Friends

My Links

Permanent Posts

Portuguese Communities

February 2010 - Posts

Microsoft TechDays 2010 Portugal

Once again, TechDays is at the door!

As you probably know, TechDays is Microsoft's annual event, which occurs on each country. This year, Luís Alves Martins (of Cloud Computing fame) gave me the oportunity to present one of my favorite subjects: NHibernate!

The presentation will be titled Introdução ao NHibernate. I will soon post more details, but, for now, if you live in Portugal, mark the days 20, 21 and 22 of April on your calendar, and join us there!

TechDays 2010 Portugal

Bookmark and Share
Three Ways To Create An Object

Enjoy!

Type type = typeof(StringBuilder);	//can be any type
ConstructorInfo ci = type.GetConstructor(new Type [ 0 ]);
Stopwatch watch = new Stopwatch();

watch.Start();
			
for (Int32 i = 0; i < 100; ++i)
{
	StringBuilder obj = Activator.CreateInstance(type) as StringBuilder;
}

Int64 time1 = watch.ElapsedTicks;

watch.Reset();

watch.Start();

for (Int32 i = 0; i < 100; ++i)
{
	StringBuilder obj = ci.Invoke(null) as StringBuilder;
}

Int64 time2 = watch.ElapsedTicks;

DynamicMethod m = new DynamicMethod(String.Empty, typeof(Object), null, type, true);
			
ILGenerator il = m.GetILGenerator();
il.Emit(OpCodes.Newobj, ci);
il.Emit(OpCodes.Ret);
Func<Object> creator = m.CreateDelegate(typeof(Func<Object>)) as Func<Object>;

watch.Reset();

watch.Start();

for (Int32 i = 0; i < 100; ++i)
{
	StringBuilder obj = creator() as StringBuilder;
}

Int64 time3 = watch.ElapsedTicks;

Bookmark and Share
More Posts