Created
April 25, 2021 10:57
-
-
Save fantasywind/a98892ffe476e382bf59f48d47464b9a 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 SIZE = 500000; | |
const Fastify = require('fastify'); | |
const axios = require('axios'); | |
const fastify = Fastify({ | |
logger: true, | |
bodyLimit: 1024857600, | |
}); | |
fastify.post('/', (request, reply) => { | |
console.timeEnd('JSON:Transmission'); | |
reply.send({ done: true }); | |
}); | |
fastify.listen(3000, async () => { | |
const body = JSON.stringify({ | |
data: Array.from(Array(SIZE)).map((n, index) => ({ | |
index, | |
})), | |
}); | |
console.time('JSON:Transmission'); | |
axios({ | |
method: 'post', | |
url: 'http://127.0.0.1:3000', | |
data: body, | |
responseType: 'json', | |
headers: { | |
'Content-Type': 'application/json', | |
}, | |
maxBodyLength: Infinity, | |
}).then(({ data }) => { | |
console.time('JSON:Serialize'); | |
console.log(`JSON:Size:${Buffer.from(JSON.stringify({ | |
data: Array.from(Array(SIZE)).map((n, index) => ({ | |
index, | |
})), | |
}), { encoding: 'utf8' }).length}`); | |
console.timeEnd('JSON:Serialize'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment