Last week I spent half an hour comparing /coldfusion /vs /coldfusion cfscript/ vs/java cfscript/ vs /javascript cfscript/ and I was kind of surprised by the result, so I thought I would share it (+I saw on another thread some questions about cfscript javascript speed):

 * CFscript language=javascript is quite extremely buggy: issue #416
   and #417
 * CFscript is about the same speed as coldfusion
 * *CFscript language=java is 100 (!!!) times as fast as coldfusion* in
   calculating pi*.*

Especially the third point I would love to hear *why *the difference is *that* big.

Results (for the code see below):

 * JavaScript cfscript: uncheckable due to bugs, probably ~45000
   milliseconds (based on only 10000 loops multiplied by 100)
 * Coldfusion: 2000-2200 milliseconds
 * Coldfusion cfscript: 2000-2200 milliseconds
 * Java cfscript: 15-25 milliseconds

And the code:

/javascript/:



<cfscript language="javascript">
    function x(){}
    var Pi = 0;
    var n=1;
    for (i=0;i<=1000000;i++){
        Pi=Pi+(4/n)-(4/(n+2))
        n=n+4
    }
    $cf.print( Pi );
</cfscript>

/java/:
<cfscript language="java">
    double Pi = 0;
    double n=1;
    for (int i=0;i<=1000000;i++){
        Pi=Pi+(4/n)-(4/(n+2));
        n=n+4;
    }
    cf.print( Pi );
</cfscript>

/coldfusion/:
<cfset Pi = 0>
<cfset  n = 1>
<cfloop from="0" to="1000000" index="i">
<cfset Pi = Pi + (4/n)-(4/(n+2))>
<cfset n  = n+4>
</cfloop>
<cfoutput>#Pi#</cfoutput>

/cfscript/:
<cfscript>
    Pi = 0;
    n  = 1;
    for (i=0;i<=1000000;i++){
        Pi=Pi+(4/n)-(4/(n+2));
        n=n+4;
    }
</cfscript>
<cfoutput>#Pi#</cfoutput>

--
online documentation: http://openbd.org/manual/
  google+ hints/tips: https://plus.google.com/115990347459711259462
    http://groups.google.com/group/openbd?hl=en

    Join us @ http://www.OpenCFsummit.org/ Dallas, Feb 2012

Reply via email to