CF_Timer: No Debugging IP Address Required; Introducing nanoTime

gamesover

James Moberg

Posted on July 3, 2022

CF_Timer: No Debugging IP Address Required; Introducing nanoTime

While reviewing reports on Lucee's Dev Forum regarding performance differences between using an application-based CFC singleton and a global UDF, I thought I'd release our replacement for Adobe's CFTimer that I wrote back in 2013.

No more editing "Debugging IP Addresses"

If you wanted to use the built-in CFTimer function, Adobe required devs to specifically add their current IP address to the list of debugging IP addresses. This is inconvenient given that the task that it performs shouldn't really require special security... unless it's possible that Adobe's implementation of it could be compromised somehow. (Not sure, just guessing as I can't see any reason why this function requires special rules when you should be able to pass an option to suppress output under desired conditions.) Some third-party developers may not have access to CFAdmin or admin-based API functions, so they are left without any options other than to manually capture and output getTickCount(). (NOTE: I did have rules to pass a list of AllowedIPs, but the filter required a ipUtils.cfc library that is not available for public release yet due to third-party dependencies.)

Not Supported: Type="Debug"

I don't believe that developers have any way of influencing or adding to the output of Adobe's debug output. I used debug mode "once" to see what it did and then immediately disabled it and never bothered to use it again. (It can break too much if it is blindly enabled server or application-wide.)

Introducing nanoTime (already installed w/java.lang.system)

I didn't want to be required to loop over thousands or millions of iterations to compare performance differences, so the addition of nanoTime proved to be extremely beneficial as it provides accuracy down to the "one billionth of a second". It's not perfect, but it is at least an option.

Check out the differences between nanoTime and using millesconds.

Java System.nanoTime() vs System.currentTimeMillis
https://www.geeksforgeeks.org/java-system-nanotime-vs-system-currenttimemillis/

Use as CFScript

This can be called within CFScript by calling it using the following syntax.

cf_timer(type="outline", label="My timer test", nano=true){
    performAnythingThatYouWantToMeasure();
}
Enter fullscreen mode Exit fullscreen mode

Anyway, here's the CFTag. Enjoy!

https://gist.github.com/JamoCA/905c21d434cbef10b03cf799f9b93f16

💖 💪 🙅 🚩
gamesover
James Moberg

Posted on July 3, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related