using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
textBox1.AppendText("test start" + Environment.NewLine);
this.hoge1();
this.hoge2();
this.hoge3();
this.hoge4();
}
void hoge1()
{
Stopwatch sw = new Stopwatch();
sw.Reset();
sw.Start();
for (int i = 0; i < 10; i++)
{
for (int r = 0; r < 100000; r++)
{
int R = r / 4; if (r % 4 == 1) R++;
int G = r / 4; if (r % 4 == 2) G++;
int B = r / 4; if (r % 4 == 3) B++;
}
}
sw.Stop();
textBox1.AppendText(
((double)sw.ElapsedTicks
/ (double)Stopwatch.Frequency).ToString()
+ Environment.NewLine);
}
void hoge2()
{
Stopwatch sw = new Stopwatch();
sw.Reset();
sw.Start();
for (int i = 0; i < 10; i++)
{
for (int r = 0; r < 100000; r++)
{
int R = r >> 2; if ((r & 0x3) == 1) R++;
int G = r >> 2; if ((r & 0x3) == 2) G++;
int B = r >> 2; if ((r & 0x3) == 3) B++;
}
}
sw.Stop();
textBox1.AppendText(
((double)sw.ElapsedTicks
/ (double)Stopwatch.Frequency).ToString()
+ Environment.NewLine);
}
void hoge3()
{
Stopwatch sw = new Stopwatch();
sw.Reset();
sw.Start();
for (int i = 0; i < 10; i++)
{
for (int r = 0; r < 100000; r++)
{
int R = r / 4 + (r + 3) % 4 / 3;
int G = r / 4 + (r + 2) % 4 / 3;
int B = r / 4 + (r + 1) % 4 / 3;
}
}
sw.Stop();
textBox1.AppendText(
((double)sw.ElapsedTicks
/ (double)Stopwatch.Frequency).ToString()
+ Environment.NewLine);
}
void hoge4()
{
Stopwatch sw = new Stopwatch();
sw.Reset();
sw.Start();
for (int i = 0; i < 10; i++)
{
for (int r = 0; r < 100000; r++)
{
int R = (r >> 2) + ((r + 3) & 0x3) / 3;
int G = (r >> 2) + ((r + 2) & 0x3) / 3;
int B = (r >> 2) + ((r + 1) & 0x3) / 3;
}
}
sw.Stop();
textBox1.AppendText(
((double)sw.ElapsedTicks
/ (double)Stopwatch.Frequency).ToString()
+ Environment.NewLine);
}
}
}