在codeproject網站有介紹跟code。
http://www.codeproject.com/Articles/37215/Permutations-in-C-Using-Recursion
2013年12月17日 星期二
2013年8月17日 星期六
Parallel.Foreach取得目前元素之索引位置
想法:在影像處理run pixel上用了Parallel Foreach跟For,比非Parallel的快非常多,但是卻少了Index。在做pixel操作的時候有時需要知道要寫回哪裡。
實作:
byte[] byteArray = binary.Bytes; //size:307200
var query = byteArray.Select((val, idx) => new { Index = idx, Value = val });
int[] result = new int[byteArray.Length];
//平行 擇一上註解
Parallel.ForEach(query, b=>
{
if (b.Value >= 255)
{
result[b.Index] = -1;
}
} //close lambda expression
); //close method invocation
//非平行 擇一上註解
foreach (var b in query)
{
if (b.Value >= 255) result[b.Index] = -1;
}
結論:驚!! Parallel方法花了25ms。非Parallel花了17ms。Parallel for是否又比Parallel foreach?!
等國科會結束我再來比較一下Parallel for!!!
實作:
byte[] byteArray = binary.Bytes; //size:307200
var query = byteArray.Select((val, idx) => new { Index = idx, Value = val });
int[] result = new int[byteArray.Length];
//平行 擇一上註解
Parallel.ForEach(query, b=>
{
if (b.Value >= 255)
{
result[b.Index] = -1;
}
} //close lambda expression
); //close method invocation
//非平行 擇一上註解
foreach (var b in query)
{
if (b.Value >= 255) result[b.Index] = -1;
}
結論:驚!! Parallel方法花了25ms。非Parallel花了17ms。Parallel for是否又比Parallel foreach?!
等國科會結束我再來比較一下Parallel for!!!
2013年8月16日 星期五
在WPF做倒數計時器
想法:因為系統需要倒數計時器來執行拍照。
實作:
step 1: 加入System.Windows.Forms參考,並引入。
step 2: coding!
private void button1_Click(object sender, RoutedEventArgs e)
{
timer1 = new Timer();//global
timer1.Interval = 1000;
second = 5;//global
timer1.Tick+=new EventHandler(timer1_Tick);
timer1.Start();
}
private void timer1_Tick(object sender, EventArgs e)
{
if (second > 0)
{
label1.Content = second ;
second--;
}
else
{
timer1.Stop();
label1.Content = "";
BitmapImage bi = new BitmapImage(new Uri("/Image/p3.jpg", UriKind.RelativeOrAbsolute));
image1.Source = bi;
}
}
Label用FontSize調字型大小。
實作:
step 1: 加入System.Windows.Forms參考,並引入。
step 2: coding!
private void button1_Click(object sender, RoutedEventArgs e)
{
timer1 = new Timer();//global
timer1.Interval = 1000;
second = 5;//global
timer1.Tick+=new EventHandler(timer1_Tick);
timer1.Start();
}
private void timer1_Tick(object sender, EventArgs e)
{
if (second > 0)
{
label1.Content = second ;
second--;
}
else
{
timer1.Stop();
label1.Content = "";
BitmapImage bi = new BitmapImage(new Uri("/Image/p3.jpg", UriKind.RelativeOrAbsolute));
image1.Source = bi;
}
}
Label用FontSize調字型大小。
訂閱:
文章 (Atom)