Browse Source

Updated test driver to support streaming results

pull/17/head
Matthew Holt 11 years ago
parent
commit
ec3053ffb8
  1. 74
      index.html

74
index.html

@ -48,6 +48,10 @@
padding: 5px; padding: 5px;
} }
label {
white-space: nowrap;
}
button { button {
font-size: 18px; font-size: 18px;
padding: 10px 40px; padding: 10px 40px;
@ -58,10 +62,12 @@
<div class="container"> <div class="container">
<div class="text-center"> <div class="text-center">
Delimiter: <input type="text" id="delim" value="" maxlength="1" placeholder="auto"> <a href="javascript:" id="tabdelim">(Tab)</a> Delimiter: <input type="text" id="delim" value="" maxlength="1" placeholder="auto"> <a href="javascript:" id="tabdelim">(Tab)</a>
&nbsp; &nbsp; <br>
<label><input type="checkbox" id="header" checked> Header row</label> <label><input type="checkbox" id="header" checked> Header row</label>
&nbsp; &nbsp; &nbsp; &nbsp;
<label><input type="checkbox" id="dyntype" checked> Dynamic typing</label> <label><input type="checkbox" id="dyntype" checked> Dynamic typing</label>
&nbsp; &nbsp;
<label><input type="checkbox" id="stream"> Stream results</label>
</div> </div>
<br> <br>
<textarea id="tb" placeholder="CSV input">Address,City,State,Zipcode,Name,Phone Number,Group,URL <textarea id="tb" placeholder="CSV input">Address,City,State,Zipcode,Name,Phone Number,Group,URL
@ -92,32 +98,74 @@ Duke Rd & Walden Ave,Buffalo,NY,14225,Apple Store Walden Galleria,(716) 685-2762
<script> <script>
$(function() $(function()
{ {
var rowCount = 0;
var big = 10240; // 10 MB
$('#parseText').click(function() $('#parseText').click(function()
{ {
// TODO: Build in some performance logging rowCount = 0;
//var start = performance.now(); $('#parseFiles').prop('disabled', true);
if (is('stream'))
console.log("Now parsing input (not showing progress for massive performance boost)...");
// TODO: Build in some performance logging?
var start = performance.now();
var results = $.parse($('#tb').val(), userConfig()); var results = $.parse($('#tb').val(), userConfig());
//var end = performance.now(); var end = performance.now();
//console.log((end - start) + " milliseconds");
render(results); console.log(Math.round(end - start) + " ms to parse input text");
if (!is('stream'))
render(results);
else
{
console.log("Rows parsed:", rowCount);
render({"message": "Results were streamed and were not aggregated in order to save memory. See console for row count."});
}
$('#parseFiles').prop('disabled', false);
}); });
$('#parseFiles').click(function() $('#parseFiles').click(function()
{ {
rowCount = 0;
$('#parseFiles').prop('disabled', true);
var start = performance.now();
$('#fileinput1, #fileinput2').parse( $('#fileinput1, #fileinput2').parse(
{ {
before: function(file, inputElem) before: function(file, inputElem)
{ {
console.log("BEFORE", file, inputElem); console.log("BEFORE", file, inputElem);
if (file.size && file.size > big && !is('stream'))
{
if (!confirm("WARNING - " + file.name + " is a large file, but you chose not to stream the results. This could make your browser tab lock up. Continue?"))
return false;
}
if (is('stream'))
console.log("File is being parsed and the results are being streamed... (not showing progress for massive performance boost)");
}, },
error: function(err, file, elem) error: function(err, file, elem)
{ {
console.log("ERROR", err, file, elem); console.log("ERROR", err, file, elem);
if (err.name == "AbortError")
$('#parseFiles').prop('disabled', false);
}, },
complete: function(data, file, inputElem, event) complete: function(data, file, inputElem, event)
{ {
console.log("COMPLETE", data, file, inputElem, event); var end = performance.now();
render(data);
console.log("COMPLETE", file.size < big ? data : "(too big to render data here or file was streamed)", file, inputElem, event);
console.log(Math.round(end - start) + " ms to parse file");
if (file.size && file.size < big && !is('stream'))
render(data);
else
render({"message": "File too big to render here; open Developer Tools to see the console output instead"});
$('#parseFiles').prop('disabled', false);
console.log("Rows parsed:", rowCount);
}, },
config: userConfig() config: userConfig()
}); });
@ -132,11 +180,17 @@ $(function()
{ {
return { return {
delimiter: $("#delim").val(), delimiter: $("#delim").val(),
header: $('#header').is(':checked'), header: is('header'),
dynamicTyping: $('#dyntype').is(':checked') dynamicTyping: is('dyntype'),
stream: is('stream') ? function(results) { rowCount++; } : false
}; };
} }
function is(checkboxId)
{
return $('#'+checkboxId).is(':checked');
}
function render(results) function render(results)
{ {
$('#output').text(JSON.stringify(results, undefined, 2)); $('#output').text(JSON.stringify(results, undefined, 2));

Loading…
Cancel
Save