Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
patinthehat authored and Patrick committed Feb 9, 2021
1 parent d771052 commit 62fe509
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ All notable changes to `permafrost-dev/node-ray` will be documented in this file

---

## 1.5.0 - 2021-02-09

- add ability to configure Ray within a Browser environment _(host, port, etc.)_

- add `measure()` method to measure the performance of a callback or interval _(see docs)_

- add `stopTime()` method to remove either a named stopwatch, or all stopwatches if no name is provided

## 1.4.4 - 2021-02-09

- update `web` variant module
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ See [using the package](docs/usage.md).
| `ray().html(string)` | Send HTML to Ray |
| `ray().image(url)` | Display an image in Ray |
| `ray().json([…])` | Send JSON to Ray |
| `ray().measure(callable)` | Measure the performance of a callback function |
| `ray().measure()` | Begin measuring the overall time and elapsed time since previous `measure()` call |
| `ray().newScreen()` | Start a new screen |
| `ray().newScreen('title')` | Start a new named screen |
| `ray(…).notify(message)` | Display a notification |
Expand All @@ -223,6 +225,7 @@ See [using the package](docs/usage.md).
| `ray(…).showIf(true)` | Conditionally show things based on a truthy value or callable |
| `ray(…).showWhen(true)` | Conditionally show things based on a truthy value or callable |
| `ray(…).small()` | Output text smaller or bigger. Use `large` or `small`|
| `ray().stopTime(name)` | Removes a named stopwatch if specified, otherwise removes all stopwatches |
| `ray().table([…])` | Display an array of items formatted as a table; Objects and arrays are pretty-printed |
| `ray().xml(string)` | Send XML to Ray |

Expand Down
33 changes: 33 additions & 0 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,39 @@ Specifying the format is optional. It uses the [dayjs formatting](https://day.js
ray().date(new Date(), 'YYYY-MM-DD hh:mm');
```

### Measuring performance and memory usage

You can use the `measure` function to display runtime and memory usage. When `measure` is called again, the time between
this and previous call is also displayed.

```js
ray().measure();

sleep(1);

ray().measure();

sleep(2);

ray().measure();
```

![screenshot](/docs/ray/v1/images/measure.jpg)

The `measure` call optionally accepts a callable. Ray will output the time needed to run the callable and the maximum
memory used.

```js
const usleep = (milliseconds) => {
const start = new Date().getTime();
while (new Date().getTime() < start + milliseconds) { }
};

ray().measure(() => {
usleep(5000); // 5 sec
});
```

### Feature demo

Here's a sample script that demonstrates a number of the features, both basic and advanced.
Expand Down

0 comments on commit 62fe509

Please sign in to comment.