Arthur Fiorette 88c9655ba3
Axios cache interceptor v1 roadmap (#368)
* chore(deps-dev): bump axios from 0.27.2 to 1.0.0

Bumps [axios](https://github.com/axios/axios) from 0.27.2 to 1.0.0.
- [Release notes](https://github.com/axios/axios/releases)
- [Changelog](https://github.com/axios/axios/blob/v1.x/CHANGELOG.md)
- [Commits](https://github.com/axios/axios/compare/v0.27.2...v1.0.0)

---
updated-dependencies:
- dependency-name: axios
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* feat: initial changes

* feat: more docs

* docs: global config

* feat: comparison

* chore: more docs

* docs: migrate docs generator to vitepress (#403)

* chore(vitepress): add basic files

* chore(vitepress): add dev deps & scripts for use

* chore(vitepress config): change to ts for type checks

* chore(vitepress config): remove js file

* chore(vitepress theme): add custom theme css

* chore(vitepress docs): add simple home page

* chore(gitignore): ignore doc dist

* chore(favicon): add icon to head

* feat(doc-features): add features spotlight

* chore(doc footer): made with ❤️

* chore(structure): move md files into `./src`

* chore(config): re-organise

* chore: custom dev port

* feat: documentation pages

* refactor: modified config

* feat: social links

* style: formatted code

* feat: removed code groups temporarily

* fix: fixed bundlephobia svg

* docs: general documentation remake

* docs: more rewritting

Co-authored-by: arthurfiorette <arthur.fiorette@gmail.com>

* fix: change headers usage

* fix: adapters exporting changes

* fix: request doesnt execute after abortion

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Cain <75994858+cainthebest@users.noreply.github.com>
2022-12-05 22:36:31 -03:00

87 lines
2.1 KiB
JavaScript

const Benny = require('benny');
const { execSync } = require('child_process');
const { writeFileSync } = require('fs');
const path = require('path');
// Outputs into the documentation folder
const output = path.resolve(__dirname, '../docs/src/generated/benchmark.md');
const Axios = require('axios').default;
const AxiosInstance = Axios.create();
const AxiosCacheInterceptor = require('../dist/index.cjs');
const InterceptorInstance = AxiosCacheInterceptor.setupCache(Axios.create());
const AxiosCacheAdapter = require('axios-cache-adapter');
const AdapterInstance = AxiosCacheAdapter.setup({});
const config = {
port: 8734,
host: '0.0.0.0'
};
const data = {};
const runs = {};
const app = require('express')();
app.get('/:name', ({ params }, res) => {
data[params.name] ? data[params.name]++ : (data[params.name] = 1);
return res.json({
computation: Math.random(),
name: params.name
});
});
const server = app.listen(config.port, config.host);
Benny.suite(
'Benchmark Result',
Benny.add('axios', async () => {
const name = 'axios';
runs[name] ? runs[name]++ : (runs[name] = 1);
await AxiosInstance.get(`http://${config.host}:${config.port}/${name}`);
}),
Benny.add('cache-interceptor', async () => {
const name = 'cache-interceptor';
runs[name] ? runs[name]++ : (runs[name] = 1);
await InterceptorInstance.get(`http://${config.host}:${config.port}/${name}`);
}),
Benny.add('cache-adapter', async () => {
const name = 'cache-adapter';
runs[name] ? runs[name]++ : (runs[name] = 1);
await AdapterInstance.get(`http://${config.host}:${config.port}/${name}`);
}),
Benny.cycle(),
Benny.complete((summary) => {
server.close();
writeFileSync(
output,
`# Result
Run at ${new Date().toUTCString()}
Commit: ${execSync('git rev-parse HEAD').toString()}
${summary.results
.sort((a, b) => a.percentSlower - b.percentSlower)
.map(
(options) => `
${options.name.split('-').join(' ').toUpperCase()}
Operations: ${options.ops}/s
Network requests: ${data[options.name]} of ${runs[options.name]}
Performance: ${(100 - options.percentSlower).toFixed(2)}%`
)
.join('\n')}
`
);
})
);