At CFUNITED, Hemant (Engineering Manager for ColdFusion) mentioned that createUUID was speed up in ColdFusion 9. CreateUUID isn't the fastest function in the world, and has some possible scary implications in some scenarios (see this excellent blog post by Tyson Vanek) but I've made use of it for years now in my open source applications because of how easy it is to use across multiple database platforms. I decided to take a look at the speed changes and I was pretty impressed by what I found.
So my test case was relatively simple, and to be honest, I am not a big fan of 'loop and time' type tests, but I figured it would be a quick way to check. Here is what I used.
<cfsetting showdebugoutput="true">
<cftimer label="createUUID() test" type="inline">
<cfloop index="x" from="1" to="20000">
<cfset createUUID()>
</cfloop>
</cftimer>
Running under ColdFusion 8, this takes a little over 20 seconds - which meshes exactly with what Tyson mentioned in his blog post. Running the exact same code in ColdFusion 9? A bit over 2 seconds. A 10 fold increase in speed. Of course, I don't think anyone will need to create twenty thousand UUIDs at once anytime soon, but that's a pretty nifty speed increase. It's the difference between the Enterprise NX-01 and 1701!
Archived Comments
Yay!
It may be a minor thing, but I've been wondering about that. I've been treading carefully ever since I saw Tyson's post.
Nice! I wonder how much of the performance gain is due to the performance enhancements of CF itself. In other words, are loops faster in CF9 too?
There is a faster way to create "UUID" - createobject ( "java", "java.util.UUID"). RandomUUID (). ToString (). The difference with the createUUID() - by my count - 4 times!
@inj really? wow. I wonder why CF9 didn't use that...
@Henry: How do you know CF9 didn't use java.util.UUID? Fire up your CF9 beta, paste in Ray's code and look at the stack traces with SeeFusion and you'll probably be able to see what they used.
@inj: java.util.UUID was only made available in Java 1.5. For anyone on CF 6 or 7, (Java 1.4) they will need jug.safehaus.org.
I'm glad to see this enhancement. You don't need to create 20,000 GUIDs with createUUID() to see them start dragging down your stack traces. On my CF 8 dev server (Java 1.6_12) I can only create about 1,200 hundred GUIDs in 20 seconds (!), but I can create 200,000 in 3/4ths of a second with JUG! That's over 4,000 times faster and still beating the pants off CF9.