English 中文(简体)
2. 与代表和建筑部的关系
原标题:Speed Issues with delegates and Structs

我在结构和代表方面遇到一些速度问题,采用以下青少年应用法:

public delegate string StringGetter();
public class LocalString
{
    public LocalString(string value)
    {
        this.value = value;
    }

    public StringGetter Getter
    {
        get
        {
            return new StringGetter(this.GetValue);
        }
    }

    private string GetValue()
    {
        return value;
    }

    private string value;
}


class Program
{
    static void Main(string[] args)
    {
        var start = DateTime.Now;
        for (int i = 0; i < 2000000; i++)
        {
            var val = new LocalString( "hello World" );
            val.Getter();
        }
        Console.WriteLine((DateTime.Now - start).TotalMilliseconds);
        Console.ReadKey();
    }
}

在我机器上执行时,需要大约1.8秒钟。 如果我把结构改变到一个等级,它就在0.1秒。 我先看一下基本的组装法和开放源源代码,看看为什么和现在有一些代表的特别法,这些代表有固定目标,而I m guessing是处理箱子和在功能方法中打箱。 类型 卫理公会

另一点——如果你在2008年把电离层作为目标,则电离层3.5比你在VS2010年把电离层作为目标时更快。 我没有说明为什么如此。

欢迎任何意见/更好的启迪......

Regards Lee

最佳回答

很难准确回答,《刑法》支持代表是打碎的坚果。 我的最好的猜测是,要从结构价值中排除/固化所需的间接费用。 这位代表的号召是,首先把价值推到箱子里,这样就能够被点名。 在发出呼吁后,这种方法的任何副作用都必须与原结构相重复。 这比简单呼吁参考类型的方法昂贵,其速度是very。 我看不出任何证据来证明建筑价值(比奇)的活度,但可能有些地方。

问题回答

暂无回答




相关问题
Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How do I compare two decimals to 10 decimal places?

I m using decimal type (.net), and I want to see if two numbers are equal. But I only want to be accurate to 10 decimal places. For example take these three numbers. I want them all to be equal. 0....

Exception practices when creating a SynchronizationContext?

I m creating an STA version of the SynchronizationContext for use in Windows Workflow 4.0. I m wondering what to do about exceptions when Post-ing callbacks. The SynchronizationContext can be used ...

Show running instance in single instance application

I am building an application with C#. I managed to turn this into a single instance application by checking if the same process is already running. Process[] pname = Process.GetProcessesByName("...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...

热门标签