2018-01-26 00:09:55 +08:00
|
|
|
'use strict';
|
|
|
|
const common = require('../common.js');
|
|
|
|
const PORT = common.PORT;
|
|
|
|
|
|
|
|
const bench = common.createBenchmark(main, {
|
2020-02-13 02:33:33 +08:00
|
|
|
res: ['normal', 'setHeader', 'setHeaderWH'],
|
|
|
|
duration: 5
|
2018-01-26 00:09:55 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
const type = 'bytes';
|
|
|
|
const len = 4;
|
|
|
|
const chunks = 0;
|
|
|
|
const chunkedEnc = 0;
|
|
|
|
const c = 50;
|
|
|
|
|
|
|
|
// normal: writeHead(status, {...})
|
|
|
|
// setHeader: statusCode = status, setHeader(...) x2
|
|
|
|
// setHeaderWH: setHeader(...), writeHead(status, ...)
|
2020-02-13 02:33:33 +08:00
|
|
|
function main({ res, duration }) {
|
2018-01-26 00:09:55 +08:00
|
|
|
process.env.PORT = PORT;
|
2019-03-26 12:21:27 +08:00
|
|
|
const server = require('../fixtures/simple-http-server.js')
|
2018-01-26 00:09:55 +08:00
|
|
|
.listen(PORT)
|
2019-02-05 14:06:08 +08:00
|
|
|
.on('listening', () => {
|
2020-02-13 02:33:33 +08:00
|
|
|
const path = `/${type}/${len}/${chunks}/${res}/${chunkedEnc}`;
|
2018-01-26 00:09:55 +08:00
|
|
|
|
|
|
|
bench.http({
|
|
|
|
path: path,
|
2020-02-13 02:33:33 +08:00
|
|
|
connections: c,
|
|
|
|
duration
|
2019-02-05 14:06:08 +08:00
|
|
|
}, () => {
|
2018-01-26 00:09:55 +08:00
|
|
|
server.close();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|