Last active
December 17, 2015 22:39
-
-
Save Measter/5683984 to your computer and use it in GitHub Desktop.
Color Benchmark
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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