C# - no riesco a verificare la velocità dei Generics

venerdì 27 novembre 2009 - 23.56

cosmopsis Profilo | Junior Member

A scopo didattico, per verificare la velocità dei Generics rispetto agli Object ho implementato questo programmino.
Creata classe Obj.cs

class Obj : IDisposable {
public Object t;
public Object u;

public Obj(Object _t, Object _u){
t = _t;
u = _u;
}
~Obj() {
Dispose();
}
public void Dispose()
{
GC.SuppressFinalize(this);
}
}

Creata classe Gen.cs
class Gen<T, U> : IDisposable {
public T t;
public U u;

public Gen(T _t, U _u){
t = _t;
u = _u;
}
~Gen() {
Dispose();
}
public void Dispose()
{
GC.SuppressFinalize(this);
}

}

Il main è:
DateTime tempo1 = new DateTime();
DateTime tempo2 = new DateTime();
const long LIM = 1000000;

tempo1 = DateTime.Now;
for (int i = 0; i <= LIM; i++) {
Obj ob = new Obj(10.236, 2005);
Console.WriteLine((double)ob.t + " - " + (int)ob.u);
}
tempo2 = DateTime.Now;
Console.WriteLine("Tempo iniziale: {0}; Tempo finale: {1}", tempo1, tempo2);
Console.Read();

tempo1 = DateTime.Now;
for (int i = 0; i <= LIM; i++) {
Gen<double, int> g = new Gen<double, int>(10.236, 2005);
Console.WriteLine(g.t + " - " + g.u);
}
tempo2 = DateTime.Now;
Console.WriteLine("Tempo iniziale: {0}; Tempo finale: {1}", tempo1, tempo2);
Console.Read();

Il problema sta nel fatto che non riesco a verificare la loro velocità rispetto "ai più obsoleti" Object. Dov'è l'errore che ho commesso???
ciao
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?

Dopo esserti registrato potrai chiedere
aiuto sul nostro Forum oppure aiutare gli altri

Consulta le Stanze disponibili.

Registrati ora !
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5