mirror of
https://github.com/arthurfiorette/axios-cache-interceptor.git
synced 2025-12-08 17:36:16 +00:00
* build(deps-dev): bump @biomejs/biome from 1.5.3 to 1.9.0 Bumps [@biomejs/biome](https://github.com/biomejs/biome/tree/HEAD/packages/@biomejs/biome) from 1.5.3 to 1.9.0. - [Release notes](https://github.com/biomejs/biome/releases) - [Changelog](https://github.com/biomejs/biome/blob/main/CHANGELOG.md) - [Commits](https://github.com/biomejs/biome/commits/cli/v1.9.0/packages/@biomejs/biome) --- updated-dependencies: - dependency-name: "@biomejs/biome" dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * code --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Arthur Fiorette <me@arthur.place>
107 lines
2.3 KiB
JavaScript
107 lines
2.3 KiB
JavaScript
const Benny = require('benny');
|
|
const { execSync } = require('node:child_process');
|
|
const { writeFileSync } = require('node:fs');
|
|
const path = require('node: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) => {
|
|
if (data[params.name] === undefined) {
|
|
data[params.name] = 1;
|
|
} else {
|
|
data[params.name]++;
|
|
}
|
|
|
|
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';
|
|
|
|
if (runs[name] === undefined) {
|
|
runs[name] = 1;
|
|
} else {
|
|
runs[name]++;
|
|
}
|
|
|
|
await AxiosInstance.get(`http://${config.host}:${config.port}/${name}`);
|
|
}),
|
|
|
|
Benny.add('cache-interceptor', async () => {
|
|
const name = 'cache-interceptor';
|
|
|
|
if (runs[name] === undefined) {
|
|
runs[name] = 1;
|
|
} else {
|
|
runs[name]++;
|
|
}
|
|
|
|
await InterceptorInstance.get(`http://${config.host}:${config.port}/${name}`);
|
|
}),
|
|
|
|
Benny.add('cache-adapter', async () => {
|
|
const name = 'cache-adapter';
|
|
|
|
if (runs[name] === undefined) {
|
|
runs[name] = 1;
|
|
} else {
|
|
runs[name]++;
|
|
}
|
|
|
|
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')}
|
|
`
|
|
);
|
|
})
|
|
);
|