Skip to content

Commit

Permalink
Add basic readme
Browse files Browse the repository at this point in the history
  • Loading branch information
kgrz committed Oct 16, 2017
1 parent fc33171 commit 1bc2085
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
babel-plugin-console-perf
=========================


A babel plugin to assist in improving JS code performance. I got this
idea when browing documentation on various `console` methods, and
discovered that there's a `console.profile` function that automatically
starts and stops the JavaScript profiler for a particular region inside
the function. I wanted to make this as seamless as possible.


How this works
--------------

This plugin looks for the comment `// profile`, maps out the function
region and does a couple of things:

1. adds a `console.profile(<function identifier>)` method to the start of the function
2. adds a `console.profileEnd()` right before the end of the function

If there are `return` statements, it checks to see if there are
statements/expressions there, and then re-assigns them to variables and
returns the variable instead. This ensures that the
statements/expressions are also profiled. For instance:


```javascript

function getHash () {
// profile
const a = 42;

return heavyCryptoFunction({ key: a });
}

```

gets converted to:


```javascript

function getHash () {
console.profile('getHash');
const a = 42;

const hash = heavyCryptoFunction({ key: a});
console.profileEnd();
return hash;
}

```

instead of:

```javascript
function getHash () {
console.profile('getHash');
const a = 42;

console.profileEnd();
return heavyCryptoFunction({ key: a });
}
```

which misses out on profiling a potentially CPU-heavy function.

0 comments on commit 1bc2085

Please sign in to comment.