Skip to content
Permalink
Browse files
Should resolve CB-1478. Added XHR and FileReader benchmarks to autobe…
…nch.
  • Loading branch information
filmaj committed Feb 22, 2013
1 parent 50141d2 commit 3905507f8ffe2fc179b1bf5860eba482d82a1e2e
Showing 1 changed file with 114 additions and 26 deletions.
@@ -19,21 +19,35 @@
under the License.
-->


<html>
<head>
<meta name="viewport" content="width=device-width,height=device-height,user-scalable=no,maximum-scale=1.0,initial-scale=1.0" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8"> <!-- ISO-8859-1 -->
<title>Cordova Mobile Spec</title>
<link rel="stylesheet" href="../master.css" type="text/css" media="screen" title="no title" charset="utf-8">
<script type="text/javascript" charset="utf-8" src="../cordova.js"></script>
<script type="text/javascript" charset="utf-8" src="uubench.js"></script>
<script type="text/javascript" charset="utf-8" src="uubench.js"></script>
<script type="text/javascript" charset="utf-8" src="licensecontents.js"></script>
<script>
var exec = cordova.require('cordova/exec');
var temp, pers, LICENSE_CONTENTS;
function $(id) { return document.getElementById(id); }

function copy_license(filesystem, callback) {
filesystem.root.getFile("LICENSE", {create: true, exclusive: false}, function(entry) {
entry.createWriter(function(writer) {
writer.onwriteend = function(evt) {
callback();
};
writer.write(LICENSE_CONTENTS);
}, function(err) {
alert('Error creating LICENSE FileWriter');
});
}, function(err) {
alert('Error copying LICENSE to a file system');
});
}

var suite = new uubench.Suite({
start:function() {
$('loading').innerHTML = "BENCHMARKING IN PROGRESS...";
@@ -54,27 +68,34 @@

document.addEventListener("deviceready", function() {
deviceReady = true;
setTimeout(function() {
suite.bench("Echo exec callbacks", function(next) {
exec(function() {
// win
next();
}, function() {
// fail
next();
}, "Echo", "echo", ["test"]);
});
suite.bench("Echo exec invocations", function(next) {
exec(function() {
// win
}, function() {
// fail
}, "Echo", "echo", ["test"]);
next();
});
suite.run();
}, 25);
}, false);
var xhr = new XMLHttpRequest();
xhr.open("GET", "../LICENSE", true);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
if (xhr.responseText.length > 0) {
LICENSE_CONTENTS = xhr.responseText;
} else {
alert('Some prereq XHR stuff to get license content failed mang.');
}
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(p_fs) {
pers = p_fs;
copy_license(pers, function() {
window.requestFileSystem(LocalFileSystem.TEMPORARY, 0, function(t_fs) {
temp = t_fs;
copy_license(temp, function() {
setTimeout(bench, 250);
});
}, function(t_e) {
alert('Failed to get TEMPORARY File System');
});
});
}, function(p_e) {
alert('Failed to get PERSISTENT File System');
});
}
};
xhr.send(null);
});

window.onload = function() {
window.setTimeout(function() {
@@ -83,7 +104,74 @@
}
}, 1000);
};

function bench() {
suite.bench("Echo exec callbacks", function(next) {
exec(function() {
// win
next();
}, function() {
// fail
next();
}, "Echo", "echo", ["test"]);
});
suite.bench("Echo exec invocations", function(next) {
exec(function() {
// win
}, function() {
// fail
}, "Echo", "echo", ["test"]);
next();
});
suite.bench("XHR to within-package 11kb asset.", function(next) {
var xhr = new XMLHttpRequest();
xhr.open("GET", "../LICENSE", true);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
if (xhr.status == 200) {
next();
} else {
alert('There was a problem during XHR file read!');
}
}
};
xhr.send(null);
});
if (temp) {
suite.bench("Get contents of 11kb asset located on TEMPORARY File System using FileReader's readAsText method.", function(next) {
temp.root.getFile("LICENSE", null, function(entry) {
entry.file(function(file) {
var reader = new FileReader();
reader.onloadend = function(evt) {
next();
};
reader.readAsText(file);
}, function(err) {
alert('Error getting File object from LICENSE file in TEMP FS.');
});
}, function(err) {
alert('Error getting LICENSE file from root of TEMP FS.');
});
});
}
if (pers) {
suite.bench("Get contents of 11kb asset located on PERSISTENT File System using FileReader's readAsText method.", function(next) {
pers.root.getFile("LICENSE", null, function(entry) {
entry.file(function(file) {
var reader = new FileReader();
reader.onloadend = function(evt) {
next();
};
reader.readAsText(file);
}, function(err) {
alert('Error getting File object from LICENSE file in PERSISTENT FS.');
});
}, function(err) {
alert('Error getting LICENSE file from root of PERSISTENT FS.');
});
});
}
suite.run();
}
</script>

</head>

0 comments on commit 3905507

Please sign in to comment.