Skip to content

Commit

Permalink
docs: updated benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurfiorette committed Feb 1, 2022
1 parent f235fd4 commit 27b9a49
Show file tree
Hide file tree
Showing 6 changed files with 1,853 additions and 2,908 deletions.
83 changes: 83 additions & 0 deletions docs/benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
//@ts-check

const Benny = require('benny');
const { execSync } = require('child_process');
const { writeFileSync } = require('fs');

const Axios = require('axios').default;
const AxiosInstance = Axios.create();

const AxiosCacheInterceptor = require('../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(
'pages/_comparison-benchmark.md',
`# 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 - Math.round(options.percentSlower)}%`
)
.join('\n')}
`
);
})
);
78 changes: 0 additions & 78 deletions docs/js/benchmark.js

This file was deleted.

5 changes: 3 additions & 2 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
"private": true,
"scripts": {
"serve": "docsify serve",
"bench": "node js/benchmark.js > pages/_comparison-benchmark.log"
"bench": "node benchmark.js"
},
"devDependencies": {
"axios": "^0.25.0",
"axios-cache-adapter": "^2.7.3",
"docsify-cli": "^4.4.3",
"express": "^4.17.2"
"express": "^4.17.2",
"benny": "^3.7.1"
}
}
25 changes: 0 additions & 25 deletions docs/pages/_comparison-benchmark.log

This file was deleted.

4 changes: 2 additions & 2 deletions docs/pages/comparison.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
## Benchmark

There's an simple
[benchmark](https://github.com/arthurfiorette/axios-cache-interceptor/blob/main/docs/js/benchmark.js)
[benchmark](https://github.com/arthurfiorette/axios-cache-interceptor/blob/main/docs/benchmark.js)
in form of a stress test to compare the performance of this library, `axios-cache-adapter`
and raw axios (without cache).

[Comparison benchmark](_comparison-benchmark.log ':include :type=code')
[Results](_comparison-benchmark.md ':include :type=code')

0 comments on commit 27b9a49

Please sign in to comment.