Skip to content

Instantly share code, notes, and snippets.

@jeresig
Last active September 5, 2017 10:43
Show Gist options
  • Save jeresig/af003831559a99af63133189e088b4e6 to your computer and use it in GitHub Desktop.
Save jeresig/af003831559a99af63133189e088b4e6 to your computer and use it in GitHub Desktop.
worker-nodes big data transfer performance
$ node test_server.js
simple: 337.425ms
simple2: 1.971ms
big data: 3385.748ms
big data stringify: 801.013ms
big string: 565.437ms
module.exports = function(data, parse) {
if (parse) {
const result = JSON.parse(data);
return result[0][0];
}
return false;
};
const workerNodes = require("worker-nodes");
const renderWorkers = new workerNodes(`${__dirname}/test_render.js`, {
maxWorkers: 1,
autoStart: true,
});
console.time("simple");
renderWorkers.call(true).then((result) => {
console.timeEnd("simple");
console.time("simple2");
renderWorkers.call(true).then((result) => {
console.timeEnd("simple2");
const bigData = [];
for (let i = 0; i < 1000; i += 1) {
const a = [];
for (let j = 0; j < 1000; j += 1) {
a.push(j);
}
bigData.push(a);
}
console.time("big data");
renderWorkers.call(bigData).then((result) => {
console.timeEnd("big data");
console.time("big data stringify");
renderWorkers.call(JSON.stringify(bigData), true).then((result) => {
console.timeEnd("big data stringify");
let bigString = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
for (let i = 0; i < 17; i += 1) {
bigString += bigString;
}
console.time("big string");
renderWorkers.call(bigString).then((result) => {
console.timeEnd("big string");
});
});
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment