小编Mic*_*iti的帖子

编译C#lambda表达性能与重叠

考虑这个课程:

/// <summary>
/// Dummy implementation of a parser for the purpose of the test
/// </summary>
class Parser
{
    public List<T> ReadList<T>(Func<T> readFunctor)
    {
        return Enumerable.Range(0, 10).Select(i => readFunctor()).ToList();
    }

    public int ReadInt32()
    {
        return 12;
    }

    public string ReadString()
    {
        return "string";
    }
}
Run Code Online (Sandbox Code Playgroud)

我尝试使用已编译的lambda表达式树生成以下调用:

Parser parser = new Parser();
List<int> list = parser.ReadList(parser.ReadInt32);
Run Code Online (Sandbox Code Playgroud)

但是,表现并不完全相同......

class Program
{
    private const int MAX = 1000000;

    static void Main(string[] args)
    {
        DirectCall();
        LambdaCall();
        CompiledLambdaCall();
    }

    static void DirectCall()
    {
        Parser …
Run Code Online (Sandbox Code Playgroud)

c# linq lambda expression-trees

15
推荐指数
2
解决办法
1837
查看次数

标签 统计

c# ×1

expression-trees ×1

lambda ×1

linq ×1