# server-timing-benchmark

> Server-side benchmark based on Server Timing API

Latest version **1.0.5** (published 2018-03-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install server-timing-benchmark
pnpm add server-timing-benchmark
yarn add server-timing-benchmark
bun add server-timing-benchmark
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.5 |
| Published | 2018-03-27 |
| First published | 2018-03-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 13.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | ysugimoto |
| Maintainers | ysugimoto |
| Keywords | servcer-timing, benchmark |

## Links

- npm: https://www.npmjs.com/package/server-timing-benchmark
- Repository: https://github.com/ysugimoto/server-timing-benchmark
- Homepage: https://github.com/ysugimoto/server-timing-benchmark#readme
- Issues: https://github.com/ysugimoto/server-timing-benchmark/issues
- npm.io page: https://npm.io/package/server-timing-benchmark

## Recent versions

- 1.0.5 (latest) — 2018-03-27
- 1.0.4 — 2018-03-27
- 1.0.3 — 2018-03-27
- 1.0.2 — 2018-03-16
- 1.0.1 — 2018-03-16
- 1.0.0 — 2018-03-16

## README

# server-timing-benchmark

Benchmark server-side using Server Timing API

## Installation

This package is available on `npmjs.org`. You can intall via `npm` command:

```
$ npm install server-timing-benchmark
```

## Usage

This package supports `http/https` module and `express`.

### http

```js
const http = require('http');
const serverTimingBenchmark = require('server-timing-benchmark');

http.createServer((req, res) => {
  // Enable middelware
  serverTimingBenchmark()(req, res);

  // Create benchmarker
  const benchmark = req.benchmark();

  // Sync function
  const someFunction = () => {
    return 'response';
  };
  res.end(benchmark('someFunction', someFunction()));
}).listen(8888);
```

Above server will respond with header:

```
Server-Timing: someFunction; dur=[ms]
```

with body of 'response'.

### express

```js
const express = require('express');
const serverTimingBenchmark = require('server-timing-benchmark');

const app = express();
app.use(serverTimingBenchmark());
app.use((req, res) => {

  // Create benchmarker
  const benchmark = req.benchmark();

  // Async function
  const promiseFunction = () => {
    return new Promise(resolve => {
        setTimeout(() => resolve('response'), 1000);
    });
  };

  promiseFunction()
    .then(benchmark('promiseFunction'))
    .then(data => res.send(data))
  ;

  // Or wrap promise function
  // benchmark('promiseFunction', promiseFunction())
  //   .then(data => res.send(data))
  // ;
});
app.listen(8888);
```

Above server will respond with header:

```
Server-Timing: promiseFunction; dur=1000
```

with body of 'response'.

## License

MIT

### Author

Yoshiaki Sugimoto

---
_Source: https://npm.io/package/server-timing-benchmark · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
