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

推荐订阅源

让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Jina AI
Jina AI
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
T
Threat Research - Cisco Blogs
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Hugging Face - Blog
Hugging Face - Blog
WordPress大学
WordPress大学
阮一峰的网络日志
阮一峰的网络日志
S
Schneier on Security
博客园 - 三生石上(FineUI控件)
P
Proofpoint News Feed
G
Google Developers Blog
Project Zero
Project Zero
小众软件
小众软件
NISL@THU
NISL@THU
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
V
Vulnerabilities – Threatpost
B
Blog RSS Feed
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
宝玉的分享
宝玉的分享
博客园 - 司徒正美
Simon Willison's Weblog
Simon Willison's Weblog
Schneier on Security
Schneier on Security
G
GRAHAM CLULEY
GbyAI
GbyAI
Recent Announcements
Recent Announcements
Cisco Talos Blog
Cisco Talos Blog
C
Cisco Blogs
C
CXSECURITY Database RSS Feed - CXSecurity.com
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
人人都是产品经理
人人都是产品经理
C
CERT Recently Published Vulnerability Notes
罗磊的独立博客
T
Tailwind CSS Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
I
Intezer
Blog — PlanetScale
Blog — PlanetScale
月光博客
月光博客
PCI Perspectives
PCI Perspectives
S
Security @ Cisco Blogs
Google Online Security Blog
Google Online Security Blog
M
MIT News - Artificial intelligence
C
Cybersecurity and Infrastructure Security Agency CISA
T
Threatpost
B
Blog
The Hacker News
The Hacker News
Attack and Defense Labs
Attack and Defense Labs
腾讯CDC
T
Tenable Blog
酷 壳 – CoolShell
酷 壳 – CoolShell

博客园 - Jeffrey Sun

Composite Application Guidance (Prism) V4 Releases! 关于文件流Seek以及Read操作的一点不满 VS2010 "内存不足" 错误补丁 微软Visual Studio 2010 第三集:幸福要敏捷 详解.NET 4.0平行任务库中必须注意的三种关系 山雨欲来风满楼, 却待山花烂漫时 - 写在.NET 4.0和Visual Studio 2010发布前夜 - Jeffrey Sun [转载]微软4月13日发布Silverlight 4 团队基础生成自动化流程之最佳实践(VI) - 系统模块化条件编译 团队基础生成自动化流程之最佳实践(V) - 使用Desktop Build 团队基础生成自动化流程之最佳实践(IV) - 重写团队基础默认生成流程 谁是你的下一行CODE 团队基础生成自动化流程之最佳实践总论(III) – 重写生成号产生机制 团队基础生成自动化流程之最佳实践总论(I) – 自动化生成流程基础 团队基础生成自动化流程之最佳实践总论(II) – 程序集版本信息 Memory Reordering/Memory Model 及其对.NET的影响 从DWG到XAML (III) – .NET中的 XPS Packaging类库及一个DWFx Packaging类库的实现 (源码) 从DWG到XAML (II) - DWFx格式解析及其和XPS的关系 从DWG到XAML (I) - 浅谈DWG历史,现状及方向 - Jeffrey Sun 当心Dictionary带来的一种隐式内存泄漏
关于Duck Typing的性能分析 - Draft
Jeffrey Sun · 2011-07-04 · via 博客园 - Jeffrey Sun

using System;
using System.Threading;
using System.Collections.Generic;
using System.Diagnostics;namespace DuckTyping
{
class Program
{
public static int Range = 10000000;static void Main(string[] args)
{
string newRange = Console.ReadLine();
if (!string.IsNullOrEmpty(newRange))
{
Range
= Int32.Parse(newRange);
}

FakeEnumerable fake

= new FakeEnumerable();
RealEnumerable real
= new RealEnumerable();
YieldEnumerable
yield = new YieldEnumerable();

Stopwatch sw

= new Stopwatch();
sw.Start();
foreach (var item in fake)
{
}

sw.Stop();
Console.WriteLine(

"Duck Typing : {0}",sw.ElapsedMilliseconds);
sw.Reset();
sw.Start();
foreach (var item in real)
{
}

sw.Stop();
Console.WriteLine(

"Interface compl: {0}", sw.ElapsedMilliseconds); sw.Reset();
sw.Reset();
sw.Start();
foreach (var item in yield)
{
}

sw.Stop();
Console.WriteLine(

"Yield compl: {0}", sw.ElapsedMilliseconds);

Console.ReadKey();
}
}

public class FakeEnumerable
{
public FakeEnumerator GetEnumerator()
{
return new FakeEnumerator();
}
}
public class FakeEnumerator
{
public FakeEnumerator()
{
this.Current = 1;
}
public int Current {get;set;}public bool MoveNext()
{
Current
++;
return Current < Program.Range;
}
}
public class RealEnumerable : IEnumerable<int>
{
public IEnumerator<int> GetEnumerator()
{
return new RealEnumerator();
}

System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{

throw new NotImplementedException();
}
}
public class RealEnumerator : IEnumerator<int>
{
private int current;public RealEnumerator()
{
this.current = 0;
}
public int Current
{
get { return this.current; }
}
public void Dispose()
{
}
object System.Collections.IEnumerator.Current
{
get { return this.current; }
}
public bool MoveNext()
{
current
++;
return current < Program.Range;
}
public void Reset()
{
throw new NotImplementedException();
}
}
public class YieldEnumerable : IEnumerable<int>
{
private static int index = 0;public IEnumerator<int> GetEnumerator()
{
while (index < Program.Range)
yield return index++;
}

System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{

throw new NotImplementedException();
}
}
}