Skip to content

Instantly share code, notes, and snippets.

@Fhernd
Created July 24, 2013 03:50
Show Gist options
  • Save Fhernd/6067950 to your computer and use it in GitHub Desktop.
Save Fhernd/6067950 to your computer and use it in GitHub Desktop.
Demostración de las ventajas de rendimiento del operador bitwise desplazamiento a la derecha (Right shift) en C#.
class RendimientoDesplazamientoDerecha
{
static void Main()
{
System.Diagnostics.Stopwatch cronometro = new System.Diagnostics.Stopwatch();
cronometro.Start();
byte divisionConBitWise = 3 >> 2;
cronometro.Stop();
Console.WriteLine("Tiempo transcurrido: {0}", cronometro.Elapsed.TotalMilliseconds); // 0.0005 (puede variar)
cronometro.Reset();
cronometro.Start();
byte divisionConMathPow = (byte)(3 / Math.Pow(2, 2));
Console.WriteLine("Tiempo transcurrido: {0}", cronometro.Elapsed.TotalMilliseconds); // 0.0061 (puede variar)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment