performance - 质数性能差异 ACF vs. Lucee

标签 performance coldfusion lucee

以下用于查找素数的代码在 Adob​​e ColdFusion (10) 和 Lucee (4.5) 之间在性能方面存在很大差异。在同一台机器上测试(6C i7 3930k @ 4 GHz,Windows 10 64 位,JVM 内存设置在两个 CFML 引擎上相等:JDK7 -Xms512m -Xmx2048m -XX:MaxPermSize=512m):

<cfscript>
    ticks = getTickCount();
    stopIndex   = 10000;
    primes      = [];
    divisions   = 0;
    primes.add(2);
    primes.add(3);
    n = 5;
    for (n; n < stopIndex; n += 2) {
        isPrime = true;
        d = 3;
        for (d; d < n; d++) {
            divisions++;
            if (n % d == 0) {
                isPrime = false;
                break;
            }
        }
        if (isPrime) {
            primes.add(n);
        }
    }
    ticks = (getTickCount() - ticks);
</cfscript>

<cfoutput>
    <p>
        #numberFormat(divisions)# divisions in #ticks# ms.
    </p>
    <p>
        #numberFormat(arrayLen(primes))# prime numbers found below #numberFormat(stopIndex)#.
    </p>
</cfoutput>

停止索引@ 10k
  • ACF:2​​80 毫秒
  • LUC:1300 毫秒

  • 停止索引@ 20k
  • ACF:1000 毫秒
  • LUC:4800 毫秒

  • 停止索引@ 30k
  • ACF:2​​200 毫秒
  • LUC:10500 毫秒
  • trycf.comcflive.net显示出类似的差距。

    我检查了 cfscript(与标签)是否对时间有影响,但没有。 CFML 引擎相关的服务器设置似乎也没有任何显着影响。

    性能差异的原因可能是什么?
    我怎么可能解决这个问题?


    背景:我在生产服务器上运行繁重的数学运算(几何、图像渲染)),该服务器恰好运行 Lucee,并注意到性能缓慢。

    最佳答案

    整数数学比浮点数学慢,因此由于 Lucee 将变量存储为类型的方式,它运行得更慢。如果你强制 n 为非整数 Lucee 运行速度提高 4 倍

    if ((n+1.0) % d == 0) {
    

    这种调整也使 ACF 的速度提高了一倍以上

    https://luceeserver.atlassian.net/browse/LDEV-1541

    关于performance - 质数性能差异 ACF vs. Lucee,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37037275/

    相关文章:

    Coldfusion:跨ACF11/Lucee 4.5 RestInitApplication()解决方案

    asp.net - 加速 ASP.NET 开发

    performance - Ray Tune 用于使用指定 session 目录 (!=/tmp/ray/) 进行超参数调整

    coldfusion - 我应该<CFLOCK> <CFFILE Action ="COPY"...>吗?

    mysql - Coldfusion CFQUERY w/Inner Join & Dateformat 不工作

    coldfusion - Lucee Document is empty 错误

    c - 轮询并选择手动轮询[速度]

    python - 比较 Python 中的性能 : equal versus non equal

    azure - 尝试使用 oAuth 和 REST 从 Microsoft 获取 Azure AD onPremisesSamAccountName

    ajax - 函数的参数是必需的,但未传入