Posted in ColdFusion | Posted on 08-31-2009 | 3,935 views
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.
2<cftimer label="createUUID() test" type="inline">
3 <cfloop index="x" from="1" to="20000">
4 <cfset createUUID()>
5 </cfloop>
6</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!


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.
@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.