Skip to content

Commit

Permalink
feat(Js): Adding timing of CodeChunk execution
Browse files Browse the repository at this point in the history
  • Loading branch information
beneboy committed Sep 2, 2019
1 parent e499eb4 commit b1aa9cc
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions ts/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import getStdin from 'get-stdin'
import minimist from 'minimist'
import { parse } from 'meriyah'
import { generate } from 'astring'
import { performance } from 'perf_hooks'

import fs from 'fs'
import {
Expand Down Expand Up @@ -523,6 +524,8 @@ function executeCodeChunk(code: CodeChunkExecution): void {

const chunk = code.codeChunk

let duration = 0

ast.body.forEach(statement => {
/*
Convert `const` or `let` global declarations to `var`, otherwise they are lost in subsequent eval() calls due to
Expand All @@ -544,6 +547,8 @@ function executeCodeChunk(code: CodeChunkExecution): void {

let res

const execStart = performance.now()

try {
// @ts-ignore
// eslint-disable-next-line no-eval
Expand All @@ -552,6 +557,8 @@ function executeCodeChunk(code: CodeChunkExecution): void {
setCodeError(chunk, e)
}

duration += performance.now() - execStart

console.log = oldCl

outputs.push(res)
Expand All @@ -561,6 +568,7 @@ function executeCodeChunk(code: CodeChunkExecution): void {
}
})

chunk.duration = duration
chunk.outputs = outputs.filter(o => o !== undefined)
}

Expand Down

0 comments on commit b1aa9cc

Please sign in to comment.