-
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f235fd4
commit 27b9a49
Showing
6 changed files
with
1,853 additions
and
2,908 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')} | ||
` | ||
); | ||
}) | ||
); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.