Skip to content

Instantly share code, notes, and snippets.

@Measter
Last active December 17, 2015 22:39
Show Gist options
  • Save Measter/5683984 to your computer and use it in GitHub Desktop.
Save Measter/5683984 to your computer and use it in GitHub Desktop.
Color Benchmark
using System;
using System.Diagnostics;
using System.Drawing;
namespace ColorTest
{
class Program
{
static void Main( string[] args )
{
byte b;
int loopLimit = 10000000;
Color c = Color.FromArgb( 235, 128, 053 );
Stopwatch swColor = Stopwatch.StartNew();
for( int i = 0; i < loopLimit; i++ )
{
b = c.A;
b = c.R;
b = c.G;
b = c.B;
}
swColor.Stop();
Console.WriteLine( swColor.Elapsed );
UnsafeColor uc = new UnsafeColor( c );
Stopwatch swUnsafeColor = Stopwatch.StartNew();
for( int i = 0; i < loopLimit; i++ )
{
b = uc.Alpha;
b = uc.Red;
b = uc.Green;
b = uc.Blue;
}
swUnsafeColor.Stop();
Console.WriteLine( swUnsafeColor.Elapsed );
Console.Read();
}
}
public struct UnsafeColor
{
public byte Alpha, Red, Green, Blue;
public UnsafeColor( Color color )
{
Alpha = color.A;
Red = color.R;
Green = color.G;
Blue = color.B;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment