Skip to content

Commit

Permalink
Make run clock dynamic
Browse files Browse the repository at this point in the history
  • Loading branch information
longouyang committed Aug 20, 2016
1 parent 95e12ac commit e24e8ea
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,14 +274,13 @@ var CodeEditor = React.createClass({
var code = comp.refs.editor.getCodeMirror().getValue();
var language = comp.props.language; // TODO: detect this from CodeMirror text

// TODO: make runtime clock dynamic
var runT0;
var runT0, runClockId;

var endJob = function(store, returnValue) {
clearInterval(runClockId);
var renderedReturnValue = renderReturnValue(returnValue);
comp.addResult({type: 'text', message: renderedReturnValue });
var runT1 = _.now();
comp.setState({runTime: (runT1 - runT0) + 'ms'});
comp.setState({runTime: (_.now() - runT0)/1000 + 's'});
cleanup();
}

Expand Down Expand Up @@ -462,7 +461,7 @@ var CodeEditor = React.createClass({
try {
compileCache[code] = webppl.compile(code, {debug: true});
var compileT1 = _.now();
comp.setState({compileTime: (compileT1 - compileT0) + 'ms'});
comp.setState({compileTime: (compileT1 - compileT0)/1000 + 's'});
} catch(e) {
handleCompileError(e)
return;
Expand All @@ -484,6 +483,12 @@ var CodeEditor = React.createClass({
util.seedRNG(seed);
wait(20, function() {
runT0 = _.now();

runClockId = setInterval(function() {
comp.setState({runTime: (_.now() - runT0)/1000 + 's' })
}, 1000)


prepared.run()
})

Expand Down

0 comments on commit e24e8ea

Please sign in to comment.