Skip to content

Instantly share code, notes, and snippets.

@Fhernd
Created May 21, 2014 21:32
Show Gist options
  • Save Fhernd/befd04c5db6b5f1b0ce1 to your computer and use it in GitHub Desktop.
Save Fhernd/befd04c5db6b5f1b0ce1 to your computer and use it in GitHub Desktop.
Prueba de rendimiento entre tipos no-genéricos y tipos genéricos en C#.
// ===++===
//
// OrtizOL
//
// ===--===
/*============================================================
//
// Clase: PruebaRendimientoGenericos.cs
//
// Propósito: Prueba de rendimiento entre tipos no-genéricos
// y tipos genéricos.
//
============================================================*/
using System;
using System.Diagnostics;
using System.Collections;
using System.Collections.Generic;
namespace Articulos.Cap03
{
internal class PruebaRendimientoGenericos
{
public static void Main()
{
ArrayList listaNoGenerica = new ArrayList();
List<int> listaGenerica = new List<int>();
Stopwatch cronometro = new Stopwatch();
// Agregamos 1000000 números enteros a `ListaNoGenerica`:
cronometro.Start();
for(int i = 0; i < 1000000; ++i)
{
listaNoGenerica.Add(i);
}
cronometro.Stop();
Console.WriteLine("\nTiempo transcurrido para `listaNoGenerica`: {0}ms", cronometro.Elapsed.TotalMilliseconds);
cronometro.Reset();
cronometro.Start();
// Agregamos 1000000 números enteros a `ListaGenerica`:
for(int i = 0; i < 1000000; ++i)
{
listaGenerica.Add(i);
}
cronometro.Stop();
Console.WriteLine("Tiempo transcurrido para `listaGenerica`: {0}ms\n", cronometro.Elapsed.TotalMilliseconds);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment