diff --git a/CellMachine.js b/CellMachine.js index 0746f5e..0c8f9ef 100755 --- a/CellMachine.js +++ b/CellMachine.js @@ -1285,6 +1285,8 @@ CellMachine.prototype.miss = function CellMachine_miss(d, n, cs) { CellMachine.prototype.pause = function CellMachine_pause() { /* nothing */ }; +CellMachine.prototype['x-stitch-number'] = function Cellmachine_x_stitch_number(args) { }; + CellMachine.prototype['x-vis-color'] = function Cellmachine_x_vis_color(args) { let toks = Array.from(arguments); let color = toks.shift(); diff --git a/evalJS.js b/evalJS.js index 1d95779..af54bee 100644 --- a/evalJS.js +++ b/evalJS.js @@ -422,7 +422,7 @@ function evalJS(codeText){ let captureConsole = { log: function() { - console.log.apply(console, arguments); + //console.log.apply(console, arguments); let str = ''; for (let i = 0; i < arguments.length; ++i) { if (i !== 0) str += ' '; diff --git a/parseKnitout.js b/parseKnitout.js index ac3b980..86a8042 100755 --- a/parseKnitout.js +++ b/parseKnitout.js @@ -44,13 +44,13 @@ function parseKnitout(codeText, machine, useKnitoutAsSource=false) { } else { var name = m[1]; var value = m[2]; - console.log("Comment header: '" + name + "' is '" + value + "'."); - //TODO: handle comment headers. + //console.log("Comment header: '" + name + "' is '" + value + "'."); if (name === "Carriers") { carrierNames = value.split(" "); machine.setCarriers(carrierNames); - console.log("Carrier names (front-to-back): ", carrierNames); + //console.log("Carrier names (front-to-back): ", carrierNames); } + //TODO: handle other comment headers. return; //nothing left to do with this line. } } else { diff --git a/visualizer.html b/visualizer.html index 03a98ca..95ac530 100644 --- a/visualizer.html +++ b/visualizer.html @@ -301,6 +301,87 @@ show.showKnitout.parse(knitout, false, centerView); } +//Timing code: +if (false) { + function TimingMachine() { + this.count = 0; + this.ignored = 0; + } + function countOp() { this.count += 1; } + function ignoreOp() { this.ignored += 1; } + ["in","out","inhook","releasehook","outhook","stitch","rack","pause","x-stitch-number"].forEach(function(op) { + TimingMachine.prototype[op] = ignoreOp; + }); + ["knit","tuck","split","miss"].forEach(function(op) { + TimingMachine.prototype[op] = countOp; + }); + TimingMachine.prototype.setCarriers = function() { } + TimingMachine.prototype.stretchLoops = function() { } + + const oldUpdateVisualizer = updateVisualizer; + updateVisualizer = function timeUpdateVisualizer(centerView) { + const TIMING_ITERS = 100; + + //time code generation: + let codeParse = { + min:Infinity, + total:0.0, + boxInstructions:NaN, + otherInstructions:NaN + }; + (() => { + for (let iter = 0; iter < TIMING_ITERS; ++iter) { + let before = performance.now(); + updateKnitoutMode(); + + let code = editor.getValue(); + if (isKnitout()) { + //mark up code with line numbers: + knitout = ''; + code.split('\n').forEach(function(line, lineNumber){ + knitout += line; + if (line.indexOf(';') === -1) { + knitout += ';!source:' + (lineNumber+1); + } + knitout += '\n'; + }); + } else { + knitout = evalJS(code); + } + + const tm = new TimingMachine(); + parseKnitout(knitout, tm, false); + let after = performance.now(); + codeParse.min = Math.min(codeParse.min, after - before); + codeParse.total += (after - before); + if (codeParse.boxInstructions === codeParse.boxInstructions) { + console.assert(tm.count === codeParse.boxInstructions); + console.assert(tm.ignored === codeParse.otherInstructions); + } + codeParse.boxInstructions = tm.count; + codeParse.otherInstructions = tm.ignored; + } + })(); + + //time visualization overall: + (() => { + let min = Infinity; + let total = 0.0; + for (let iter = 0; iter < TIMING_ITERS; ++iter) { + let before = performance.now(); + oldUpdateVisualizer(centerView); + let after = performance.now(); + min = Math.min(min, after - before); + total += (after - before); + } + console.log("Had " + codeParse.boxInstructions + " box-generating instructions and " + codeParse.otherInstructions + " other instructions; user code + parse took " + codeParse.min + " ms min / " + codeParse.total / TIMING_ITERS + " ms avg over " + TIMING_ITERS + " runs."); + console.log("Update took " + min + " ms min, " + (total / TIMING_ITERS) + " ms avg over " + TIMING_ITERS + " iterations."); + console.log(" User/source: " + codeParse.min + " ms min ; vis: " + (min - codeParse.min) + " ms min; vis/ins: " + (min - codeParse.min) / codeParse.boxInstructions + " ms / instruction min."); + //codeParse.total / TIMING_ITERS + " ms avg over " + TIMING_ITERS + " runs."); + //console.log("Update took " + min + " ms min, " + (total / TIMING_ITERS) + " ms avg over " + TIMING_ITERS + " iterations."); + })(); + }; +} updateVisualizer(true); @@ -335,6 +416,7 @@ console.warn("Converted dos-style line endings to unix-style.") } editor.setValue(text, -1); + updateVisualizer(!sameFile); }; console.log("reading " + file.name);