有没有办法估计这个模型的性能?

问题描述 投票:0回答:1

我不是工程师,我是 PO。

对于一个简单的答案来说,这个问题可能太复杂了,但就这样吧。

我正在尝试了解决策引擎某些设计的性能估计。该引擎将运行一系列是/否问题,并使用一个表示非平衡二叉树的模型,其中每个节点都是一个比较 - object.x >= value 吗?处理过程类似于:

  1. 检索对象
  2. 从树的顶部开始
  3. object.x > y 吗? 3a.是的,下一个节点 3b.不,下一个节点
  4. 重复步骤3直到分支结束
  5. 结果已定

有一些框架可以很容易地解决这个问题,即 Drools。或者,我认为可以通过数据库中的模型来解决。

为了简单起见,这里有一些限制/假设:

  1. 分支的最大长度为16个节点
  2. 这不是二分搜索算法,因为树不平衡/从最低到最高 每个节点都是一个比较
  3. 用于比较的所有相关数据都已检索到
  4. 比较节点的任何计算最多都是 2 个字段,具有以下任意操作数:+、-、/、*
  5. 用java/postgres编写

我如何评估该模型的性能? O 符号是什么?搜索所有 16 个节点需要多长时间?我还差得远吗

谢谢!

我尝试查找 Drools 性能估算,但找不到我希望实现的目标。

java algorithm performance architecture data-modeling
1个回答
0
投票
Of course, I can help you with that! Below is a simplified Node.js code snippet that models the described decision engine logic and provides an estimate of its performance. This code assumes that you have already obtained the object and the data needed for comparison.

function performComparison(node, object) {
    if (node.type === 'leaf') {
        // End of branch, return outcome
        return node.outcome;
    }

    const leftValue = performComparison(node.left, object);
    const rightValue = performComparison(node.right, object);

    switch (node.operator) {
        case '>':
            return leftValue > rightValue;
        case '>=':
            return leftValue >= rightValue;
        case '<':
            return leftValue < rightValue;
        case '<=':
            return leftValue <= rightValue;
        // Add more cases for other operators (+, -, /, *)
        default:
            throw new Error(`Unsupported operator: ${node.operator}`);
    }
}

// Example decision tree node
const decisionTree = {
    type: 'comparison',
    operator: '>=',
    left: { type: 'value', value: 'object.x' },
    right: { type: 'constant', value: 10 },
};

// Example object data
const object = { x: 15 };

const outcome = performComparison(decisionTree, object);
console.log('Outcome:', outcome);


Note that this code provides a basic implementation of the decision engine logic and should be adapted and extended for your specific use case and data structure.

In terms of performance and estimation of O notation, the time complexity of the decision engine is highly dependent on the depth of the decision tree. In this case the maximum branch length is 16 nodes, so in the worst case scenario he would have to traverse all 16 nodes, resulting in a time complexity of O(16) which is effectively constant time. Masu.

Note, however, that the actual performance may be affected by many factors, including computational complexity within the comparison node, hardware, and database performance. To get more accurate performance estimates, it may be necessary to implement a benchmarking mechanism and test the engine using representative data and scenarios.

Finally, if you are interested in considering performance optimizations, you can consider techniques such as memoization to avoid redundant computations and cache previously computed results.
© www.soinside.com 2019 - 2024. All rights reserved.