Skip to content

Instantly share code, notes, and snippets.

@d1rtym0nk3y
Created July 3, 2014 13:27
Show Gist options
  • Save d1rtym0nk3y/aa3a1a9503046bbb017e to your computer and use it in GitHub Desktop.
Save d1rtym0nk3y/aa3a1a9503046bbb017e to your computer and use it in GitHub Desktop.
<cfscript>
t = 'http://google.co.uk';
c = 100;
//warmup
javaGet(t);
cfmlGet(t);
benchmark('java', function() {
javaGet(t)
}, c);
echo('<hr>')
benchmark('cfml', function() {
cfmlGet(t)
}, c);
function benchmark(label, func, iter) {
var i = 1;
var results = [];
while(i<=iter) {
var s = gettickcount();
func();
var e = gettickcount();
results.append(e-s);
i++;
}
echo("<pre>
<b>#label#</b>
#iter# iterations
min: #arraymin(results)#ms
max: #arraymax(results)#ms
avg: #round(arrayavg(results))#ms
</pre>");
}
function javaGet(string url) {
var in = createobject("java", "java.net.URL").init(arguments.url).openStream();
var reader = createObject("java", "java.io.BufferedReader").init(createObject("java", "java.io.InputStreamReader").init(in));
var line = reader.readLine();
var result = createobject("java", "java.lang.StringBuffer").init();
while(!isNull(line)) {
result.append(line);
line = reader.readLine();
}
return result;
}
function cfmlGet(string url) {
http url="#arguments.url#";
return cfhttp.filecontent;
}
</cfscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment