Skip to content

Instantly share code, notes, and snippets.

@20chan
Last active July 8, 2017 16:19
Show Gist options
  • Save 20chan/62da0302600f5a025d3076a580a33881 to your computer and use it in GitHub Desktop.
Save 20chan/62da0302600f5a025d3076a580a33881 to your computer and use it in GitHub Desktop.
이미지를 Flatten한 배열로 가져올 때 속도 비교
static Bitmap b;
static void Main(string[] args)
{
var methods = typeof(Program).GetMethods(BindingFlags.Static | BindingFlags.NonPublic);
foreach (var method in methods)
{
if (method.GetCustomAttribute<GetRuntime>() != null)
{
int range = 10;
DateTime before = DateTime.Now;
for (int t = 0; t <= range; t++)
{
method.Invoke(null, null);
}
DateTime after = DateTime.Now;
Console.WriteLine($"{method.Name}을 {range}번 돌려본 결과 {(after - before).TotalMilliseconds} 밀리세컨드 걸림!");
}
}
Console.ReadLine();
}
[GetRuntime]
static void Memory()
{
unsafe
{
b = new Bitmap(@"D:\Image\design\치워\히오스.png");
var bitmapData = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), System.Drawing.Imaging.ImageLockMode.ReadWrite, b.PixelFormat);
var length = bitmapData.Stride * bitmapData.Height;
byte[] bytes = new byte[length];
Marshal.Copy(bitmapData.Scan0, bytes, 0, length);
b.UnlockBits(bitmapData);
}
}
[GetRuntime]
static void For()
{
Color[] data = new Color[b.Width * b.Height];
for(int x = 0; x < b.Width; x++)
for(int y = 0; y < b.Height; y++)
data[x + y * b.Width] = b.GetPixel(x, y);
}
}
class GetRuntime : Attribute
{
}
Memory을 10번 돌려본 결과 615.4583 밀리세컨드 걸림!
For을 10번 돌려본 결과 17706.2605 밀리세컨드 걸림!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment