惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Attack and Defense Labs
Attack and Defense Labs
The GitHub Blog
The GitHub Blog
C
Check Point Blog
博客园_首页
MongoDB | Blog
MongoDB | Blog
N
Netflix TechBlog - Medium
F
Full Disclosure
Microsoft Security Blog
Microsoft Security Blog
爱范儿
爱范儿
Recent Announcements
Recent Announcements
阮一峰的网络日志
阮一峰的网络日志
G
GRAHAM CLULEY
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
T
Threat Research - Cisco Blogs
C
Cybersecurity and Infrastructure Security Agency CISA
V
Vulnerabilities – Threatpost
K
Kaspersky official blog
博客园 - 司徒正美
S
Schneier on Security
T
The Exploit Database - CXSecurity.com
Project Zero
Project Zero
云风的 BLOG
云风的 BLOG
Cisco Talos Blog
Cisco Talos Blog
Know Your Adversary
Know Your Adversary
雷峰网
雷峰网
V
V2EX - 技术
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Spread Privacy
Spread Privacy
罗磊的独立博客
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
S
Security Affairs
SecWiki News
SecWiki News
Schneier on Security
Schneier on Security
O
OpenAI News
Jina AI
Jina AI
PCI Perspectives
PCI Perspectives
Cyberwarzone
Cyberwarzone
Y
Y Combinator Blog
Apple Machine Learning Research
Apple Machine Learning Research
B
Blog RSS Feed
I
InfoQ
D
Docker
P
Palo Alto Networks Blog
Recorded Future
Recorded Future
M
MIT News - Artificial intelligence
博客园 - Franky
B
Blog
Scott Helme
Scott Helme
博客园 - 叶小钗
D
DataBreaches.Net

博客园 - J.D Huang

TinyDO:可能是WP首个支持中文语音识别的待办事项APP Internet TV 影音娱乐新生活 Windows Phone Developer Tools CTP 发布了! Python - 默认参数的一次性求值 Python小技巧 – True or False - J.D Huang Python小技巧 - 子串查找 - J.D Huang 新的个人博客@ http://thinkbot.info MeeGo:下一个Android? Windows Mobile 6.5.3 Developer Tool Kit 发布了 塞班(Symbian)开源了(包括Symbian 3和S60等) Windows Mobile 6.5 SDK 发布了 (2月17日更新) C#4.0新特性之(四)新的LINQ扩展方法-Zip() C#4.0新特性之(三)协变与逆变 C#4.0新特性之(二)命名参数,可选参数与COM互操作 C#4.0新特性之(一)动态查找 Android手机防盗工具DroidGuard Simple HostMonitor 实用的网管小工具 Office Mobile 2010 Beta 发布了! - J.D Huang Lambda演算与科里化(Currying)
试了一下.Net Fx 4.0中的Parallel - J.D Huang
J.D Huang · 2009-11-15 · via 博客园 - J.D Huang

        static string[] arr = Directory.GetFiles(
                                          
@"C:\Users\Public\Pictures\Sample Pictures"
                                          
"*.jpg");

        
//这里Spin的数值最好自行modify一下,我的是Q6600的机子 
        static void SimulateProcessing() { Thread.SpinWait(1000000000); } 
        
static string TID get return " TID = " + Thread.CurrentThread.Mana
gedThreadId.ToString(); }
 }

        
static void Main(string[] args)
        
{
            
//foreach (string name in arr)
            
//{
            
//    Program.SimulateProcessing();
            
//    Console.WriteLine(name + TID);
            
//}

            Parallel.ForEach(arr, (
string name) =>
            
{
                Program.SimulateProcessing();
                Console.WriteLine(name 
+ TID);
            }
);
            Console.ReadLine();
        }

采用并行的Foreach效果的确很明显.不仅仅是指派了多个线程,对cpu的利用率也高很多,
见下面两图比较:
原来的foraech:

使用parallel的foreach:

有兴趣的朋友可以对parallel相应的类库做一下逆向工程分析一下it的原理;-)