Skip to content

Instantly share code, notes, and snippets.

@fantasywind
Created April 25, 2021 10:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fantasywind/a98892ffe476e382bf59f48d47464b9a to your computer and use it in GitHub Desktop.
Save fantasywind/a98892ffe476e382bf59f48d47464b9a to your computer and use it in GitHub Desktop.
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