Skip to content

Instantly share code, notes, and snippets.

@jshirley
Created February 26, 2012 15:11
Show Gist options
  • Select an option

  • Save jshirley/1917251 to your computer and use it in GitHub Desktop.

Select an option

Save jshirley/1917251 to your computer and use it in GitHub Desktop.
Demonstrates that memory is not released from XML parsing (during .apply)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>DataSchema Tests</title>
<script type="text/javascript" src="../../../build/yui/yui.js"></script>
</head>
<body class="yui3-skin-sam">
<h1>DataSchema Performance Tests</h1>
<p><select id="testSelector"></select> <input type="button" value="Run Test" id="btnRun" disabled=true></p>
<script type="text/javascript">
YUI({
filter: (window.location.search.match(/[?&]filter=([^&]+)/) || [])[1] || 'min',
allowRollup: false,
useBrowserConsole: false
}).use("console", "profiler", "dump", "datatype", "dataschema", function(Y) {
// Set up the page
var btnRun = Y.one("#btnRun"),
selectTest = Y.one("#testSelector"),
allTests = [],
myConsole = new Y.Console().render();
btnRun.set("disabled", false);
Y.on("click", function(e){
run();
}, btnRun);
function register(testName, testFn) {
var index = allTests.length;
allTests[index] = testFn;
var optionEl = document.createElement("option");
optionEl.innerHTML = testName;
selectTest.appendChild(optionEl);
}
function run() {
var test = selectTest.get("value");
Y.log("Starting " + test, "info", "perf");
allTests[selectTest.get("selectedIndex")].apply(this);
Y.log(test + " completed", "info", "perf");
}
register("Test XML schema repeated parsing", function() {
var schema = {
resultListLocator: "item",
resultFields: [{key:"type", locator:"@type"}, {key:"rank", parser:Y.DataType.Number.parse}, "name", {key:"subnameatt", locator:"subitem/name/@type"}, {key:"age", locator:"subitem/age", parser:"number"}]
},
data_in = "<myroot rootatt='5'><top>topvalue</top><second nested='nestedsecond' /><allitems><livehere>",
data_out, i=0, startTime, endTime, parsed_in;
//Populate data
for(i=0; i<100; i++) {
data_in += "<item type='foo'><name type='nametype0'>Abc</name><rank>"+i+"</rank><subitem><name type='subnametype0'>subABC</name><age>10</age></subitem></item>";
}
data_in += "</livehere></allitems></myroot>";
startTime = new Date();
for(i=0; i<100; i++) {
parsed_in = Y.DataType.XML.parse(data_in);
Y.log('Iteration ' + i);
// The test
data_out = Y.DataSchema.XML.apply(schema, parsed_in);
}
endTime = new Date();
Y.log(endTime-startTime);
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment