Last active
March 12, 2021 16:22
-
-
Save yadomi/479a486e9393df609da26ad255fc5315 to your computer and use it in GitHub Desktop.
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
const express = require('express'); | |
const app = express(); | |
const port = 3000; | |
const bodyParser = require('body-parser').json({ limit: '40mb' }); | |
function responseTime(req, res, next) { | |
const start = process.hrtime(); | |
res.on('finish', () => { | |
const elapsedHrTime = process.hrtime(start); | |
const elapsedTimeInMs = elapsedHrTime[0] * 1000 + elapsedHrTime[1] / 1e6; | |
console.log('%s : %fms', req.path, elapsedTimeInMs); | |
}); | |
next(); | |
} | |
function customJSONParser(req, res, next) { | |
let data = ''; | |
req.on('data', function (chunk) { | |
data += chunk; | |
}); | |
req.on('end', function () { | |
req.body = JSON.parse(data); | |
next(); | |
}); | |
} | |
app.use(responseTime); | |
app.post('/bodyparser', bodyParser, (req, res) => res.send('ok')); | |
app.post('/customparser', customJSONParser, (req, res) => res.send('ok')); | |
app.post('/noparser', (req, res) => res.send('ok')); | |
app.listen(port, () => { | |
console.log(`Example app listening at http://localhost:${port}`); | |
}); | |
/* | |
for i in {1..50}; do | |
curl -X POST -H "Content-Type: application/json" -d @./prefetched_data.json http://localhost:3000/noparser | |
done | |
*/ |
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
Example app listening at http://localhost:3000 | |
/customparser : 199.639283ms | |
/customparser : 158.116242ms | |
/customparser : 139.22439ms | |
/customparser : 180.091602ms | |
/customparser : 217.681586ms | |
/customparser : 172.449014ms | |
/customparser : 161.213945ms | |
/customparser : 155.15234ms | |
/customparser : 182.308572ms | |
/customparser : 162.155039ms | |
/customparser : 137.048819ms | |
/customparser : 164.45414ms | |
/customparser : 221.564046ms | |
/customparser : 145.110558ms | |
/customparser : 162.532367ms | |
/customparser : 153.213564ms | |
/customparser : 183.441766ms | |
/customparser : 165.740644ms | |
/customparser : 181.128721ms | |
/customparser : 161.238084ms | |
/customparser : 164.630121ms | |
/customparser : 154.260714ms | |
/customparser : 191.395748ms | |
/customparser : 136.361023ms | |
/customparser : 184.794958ms | |
/customparser : 196.500766ms | |
/customparser : 155.958258ms | |
/customparser : 186.504525ms | |
/customparser : 164.862547ms | |
/customparser : 157.099748ms | |
/customparser : 156.32764ms | |
/customparser : 187.740833ms | |
/customparser : 173.564101ms | |
/customparser : 161.290756ms | |
/customparser : 168.073194ms | |
/customparser : 158.132257ms | |
/customparser : 182.405225ms | |
/customparser : 157.296821ms | |
/customparser : 157.951096ms | |
/customparser : 149.944262ms | |
/customparser : 195.245427ms | |
/customparser : 133.958814ms | |
/customparser : 158.922453ms | |
/customparser : 168.183048ms | |
/customparser : 216.565111ms | |
/customparser : 136.532334ms | |
/customparser : 156.823832ms | |
/customparser : 208.872034ms | |
/customparser : 141.004031ms | |
/customparser : 170.383808ms | |
Example app listening at http://localhost:3000 | |
/bodyparser : 241.395844ms | |
/bodyparser : 167.709473ms | |
/bodyparser : 166.180132ms | |
/bodyparser : 162.604896ms | |
/bodyparser : 198.604314ms | |
/bodyparser : 139.741458ms | |
/bodyparser : 158.615573ms | |
/bodyparser : 213.460202ms | |
/bodyparser : 155.213706ms | |
/bodyparser : 161.936912ms | |
/bodyparser : 149.113155ms | |
/bodyparser : 250.842438ms | |
/bodyparser : 142.158716ms | |
/bodyparser : 171.789269ms | |
/bodyparser : 182.556322ms | |
/bodyparser : 183.954664ms | |
/bodyparser : 173.140769ms | |
/bodyparser : 135.221308ms | |
/bodyparser : 155.579977ms | |
/bodyparser : 172.334365ms | |
/bodyparser : 162.335591ms | |
/bodyparser : 182.613277ms | |
/bodyparser : 155.638365ms | |
/bodyparser : 161.042655ms | |
/bodyparser : 150.666316ms | |
/bodyparser : 184.047986ms | |
/bodyparser : 133.133297ms | |
/bodyparser : 167.863416ms | |
/bodyparser : 200.235841ms | |
/bodyparser : 145.121059ms | |
/bodyparser : 146.667138ms | |
/bodyparser : 152.423825ms | |
/bodyparser : 174.546357ms | |
/bodyparser : 175.350878ms | |
/bodyparser : 177.33377ms | |
/bodyparser : 153.647248ms | |
/bodyparser : 182.584538ms | |
/bodyparser : 139.230466ms | |
/bodyparser : 152.198966ms | |
/bodyparser : 180.666169ms | |
/bodyparser : 202.510372ms | |
/bodyparser : 141.658906ms | |
/bodyparser : 164.710453ms | |
/bodyparser : 204.983322ms | |
/bodyparser : 140.329161ms | |
/bodyparser : 155.813073ms | |
/bodyparser : 159.658085ms | |
/bodyparser : 160.845341ms | |
/bodyparser : 158.805366ms | |
/bodyparser : 157.196298ms | |
Example app listening at http://localhost:3000 | |
/noparser : 4.363301ms | |
/noparser : 0.68213ms | |
/noparser : 0.425232ms | |
/noparser : 0.429087ms | |
/noparser : 0.440448ms | |
/noparser : 0.380363ms | |
/noparser : 0.427211ms | |
/noparser : 0.447522ms | |
/noparser : 0.416036ms | |
/noparser : 0.634677ms | |
/noparser : 0.32591ms | |
/noparser : 0.392367ms | |
/noparser : 0.553544ms | |
/noparser : 0.474316ms | |
/noparser : 0.397855ms | |
/noparser : 0.486129ms | |
/noparser : 0.339219ms | |
/noparser : 0.322496ms | |
/noparser : 0.376357ms | |
/noparser : 0.37077ms | |
/noparser : 0.410175ms | |
/noparser : 0.338254ms | |
/noparser : 0.324439ms | |
/noparser : 0.492079ms | |
/noparser : 0.325762ms | |
/noparser : 0.336741ms | |
/noparser : 0.302867ms | |
/noparser : 0.368071ms | |
/noparser : 0.426378ms | |
/noparser : 0.445174ms | |
/noparser : 0.370928ms | |
/noparser : 0.344936ms | |
/noparser : 0.310336ms | |
/noparser : 0.369327ms | |
/noparser : 0.363802ms | |
/noparser : 0.332323ms | |
/noparser : 0.322526ms | |
/noparser : 0.323123ms | |
/noparser : 0.468534ms | |
/noparser : 0.353477ms | |
/noparser : 0.324817ms | |
/noparser : 0.30905ms | |
/noparser : 0.323495ms | |
/noparser : 0.316115ms | |
/noparser : 0.311731ms | |
/noparser : 0.430025ms | |
/noparser : 0.320643ms | |
/noparser : 0.323249ms | |
/noparser : 0.313192ms | |
/noparser : 0.314354ms |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment