-
Notifications
You must be signed in to change notification settings - Fork 0
/
performance.cfm
127 lines (93 loc) · 3.4 KB
/
performance.cfm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<cfif (not structKeyExists(VARIABLES, "THISTAG")) or (not THISTAG.hasEndTag)>
<cfexit>
</cfif>
<!--- BEGIN: attributes --->
<cfparam name="ATTRIBUTES.type" type="string" default="dump"> <!--- "dump", "inline", "outline", "comment" --->
<cfparam name="ATTRIBUTES.label" type="string" default="PERFORMANCE">
<cfparam name="ATTRIBUTES.abort" type="boolean" default="false">
<cfparam name="ATTRIBUTES.nano" type="boolean" default="true">
<cfparam name="ATTRIBUTES.returnType" type="string" default=""> <!--- "ns", "μs", "ms", "s" --->
<cfparam name="ATTRIBUTES.variable" type="string" default="">
<!--- END: attributes --->
<cfif THISTAG.executionMode eq "start">
<cfif ATTRIBUTES.nano>
<cfset LOCAL.start = createObject("java", "java.lang.System").nanoTime()>
<cfelse>
<cfset LOCAL.start = getTickCount()>
</cfif>
</cfif>
<cfif THISTAG.executionMode eq "end">
<cfif ATTRIBUTES.nano>
<cfset LOCAL.end = createObject("java", "java.lang.System").nanoTime()>
<cfelse>
<cfset LOCAL.end = getTickCount()>
</cfif>
<cfset LOCAL.final = (LOCAL.end - LOCAL.start)>
<cfif not len(ATTRIBUTES.returnType)>
<cfif ATTRIBUTES.nano>
<cfif LOCAL.final gte 10000000000>
<cfset ATTRIBUTES.returnType = "s">
<cfelse>
<cfset ATTRIBUTES.returnType = "ms">
</cfif>
<cfelse>
<cfif LOCAL.final gte 10000>
<cfset ATTRIBUTES.returnType = "s">
<cfelse>
<cfset ATTRIBUTES.returnType = "ms">
</cfif>
</cfif>
</cfif>
<cfswitch expression="#ATTRIBUTES.returnType#">
<cfcase value="ns nanoseconds" delimiters=" ">
<cfif ATTRIBUTES.nano>
<cfset PERFORMANCE["Result"] = (LOCAL.final & " ns")>
<cfelse>
<cfset PERFORMANCE["Result"] = ((LOCAL.final * 1000000) & " ns")>
</cfif>
</cfcase>
<cfcase value="μs microseconds" delimiters=" ">
<cfif ATTRIBUTES.nano>
<cfset PERFORMANCE["Result"] = ((LOCAL.final / 1000) & " μs")>
<cfelse>
<cfset PERFORMANCE["Result"] = ((LOCAL.final * 1000) & " μs")>
</cfif>
</cfcase>
<cfcase value="ms milliseconds" delimiters=" ">
<cfif ATTRIBUTES.nano>
<cfset PERFORMANCE["Result"] = ((LOCAL.final / 1000000) & " ms")>
<cfelse>
<cfset PERFORMANCE["Result"] = (LOCAL.final & " ms")>
</cfif>
</cfcase>
<cfcase value="s seconds" delimiters=" ">
<cfif ATTRIBUTES.nano>
<cfset PERFORMANCE["Result"] = ((LOCAL.final / 1000000000) & " s")>
<cfelse>
<cfset PERFORMANCE["Result"] = ((LOCAL.final / 1000) & " s")>
</cfif>
</cfcase>
<cfdefaultcase>
<cfset PERFORMANCE["Result"] = LOCAL.final>
</cfdefaultcase>
</cfswitch>
<cfif len(ATTRIBUTES.variable)>
<cfset CALLER[ATTRIBUTES.variable] = PERFORMANCE["Result"]>
<cfelse>
<cfswitch expression="#ATTRIBUTES.type#">
<cfcase value="inline">
<cfoutput>#( len(ATTRIBUTES.label) ? (encodeForHtml(ATTRIBUTES.label) & " ") : "" )##PERFORMANCE["Result"]#</cfoutput>
</cfcase>
<cfcase value="outline">
<cfoutput><fieldset><cfif len(ATTRIBUTES.label)><legend>#encodeForHtml(ATTRIBUTES.label)#</legend></cfif>#PERFORMANCE["Result"]#</fieldset></cfoutput>
</cfcase>
<cfcase value="comment">
<cfoutput><!-- #( len(ATTRIBUTES.label) ? encodeForHtml(ATTRIBUTES.label) : "" )# #PERFORMANCE["Result"]# --></cfoutput>
</cfcase>
<cfdefaultcase>
<cfdump label="#ATTRIBUTES.label#" var="#PERFORMANCE#" abort="#ATTRIBUTES.abort#">
</cfdefaultcase>
</cfswitch>
</cfif>
<cfif ATTRIBUTES.abort><cfabort></cfif>
</cfif>