Micro optimisations iterating through a tree in C#

前端 未结 3 899
情歌与酒
情歌与酒 2021-01-14 16:29

I\'m working on a massive number crunching project. I\'ve been optimising everything since the start as I knew it would be important. Doing performance anal

3条回答
  •  甜味超标
    2021-01-14 17:19

    Just some code rewrite. It might help because it avoids at least two jumps.

    public ScTreeNode GetNodeForState(int rootIndex, float[] inputs)
    {
    
        ScTreeNode node = RootNodes[rootIndex].TreeNode;
    
        while (node.BranchData != null)
        {
            BranchNodeData b = node.BranchData;
            node = b.Child2;
            if (inputs[b.SplitInputIndex] <= b.SplitValue))
                node = b.Child1;
        }
    
        return node;
    
    }
    

提交回复
热议问题