Ben Nadel
On User Experience (UX) Design, JavaScript, ColdFusion, Node.js, Life, and Love.
I am the chief technical officer at InVision App, Inc - a prototyping and collaboration platform for designers, built by designers. I also rock out in JavaScript and ColdFusion 24x7.
Meanwhile on Twitter
Loading latest tweet...
Ben Nadel at Scotch On The Rock (SOTR) 2010 (Brussels) with: Ray Camden and Alison Huselid

ColdFusion JavaCast() Adds No Performance Hit

By Ben Nadel on
Tags: ColdFusion

I love the fact that Java lives up ColdFusion's skirt. That is exciting. What's not as exciting is the fact that, in a seemingly random fashion, ColdFusion has trouble performing automatic casts from ColdFusion data types to Java data types. I have never really used JavaCast() to do this unless an actual error was being thrown. However, as I start to write more and more UDFs that harness Java, I have to get into the practice of doing a JavaCast() in every required place. This will make the inner working of the UDF are as black-boxed as possible.

I was concerned that JavaCast() method calls would be adding a lot of overhead to the page request. Each method call has on overhead to it. But, I am excited to say that after some basic speed testing, JavaCast() shows no apparent processing overhead. My tests were basic; I created a Java string, initialized it with a ColdFusion string (with and without a Cast) and then Upper-Cased the string:

  • <cftimer label="No Java Cast" type="outline">
  •  
  • <!--- Loop 10,000 times. --->
  • <cfloop index="intI" from="1" to="10000" step="1">
  •  
  • <!--- Create a string based on date/time. --->
  • <cfset strText = ("Now is " & Now()) />
  •  
  • <!--- Create an upper cased string using Java. --->
  • <cfset strUpperCase = CreateObject(
  • "java",
  • "java.lang.String"
  • ).Init( strText ).ToUpperCase() />
  •  
  • </cfloop>
  •  
  • </cftimer>
  •  
  • <cftimer label="Java Cast" type="outline">
  •  
  • <!--- Create a string based on date/time. --->
  • <cfloop index="intI" from="1" to="10000" step="1">
  •  
  • <!--- Create a string based on date/time. --->
  • <cfset strText = ("Now is " & Now()) />
  •  
  • <!--- Create an upper cased string using Java. --->
  • <cfset strUpperCase = CreateObject(
  • "java",
  • "java.lang.String"
  • ).Init(
  • JavaCast( "string", strText )
  • ).ToUpperCase() />
  •  
  • </cfloop>
  •  
  • </cftimer>

Both of these tests performed anywhere from 450 ms to 550 ms. Neither of them showed any real trending towards better or worse.




Reader Comments

Post A Comment

You — Get Out Of My Dreams, Get Into My Comments
Live in the Now
Oops!
Comment Etiquette: Please do not post spam. Please keep the comments on-topic. Please do not post unrelated questions or large chunks of code. And, above all, please be nice to each other - we're trying to have a good conversation here.