Question

I've made a Node.js app that makes exactly the same thing that another solution in C#. The both app get all the javascript files from a directory recursively and execute uglify-js command to minify the files.

My project has about 150 JavaScript files to minify and the C# approach takes about 22s to do all the stuff (using threads).

After reading Node.js documentation and books, I've decided to do the Node.js way. I've already did that but I can't do reporting total time Node.js do the stuff because its asynchronous approach...

(yeah, I know, I use threads in C# that was asynchronous too)

So, what's the better way to get the Node.js app total time execution?

I'm using Node.js v0.10.13 as as win32 environment.

Was it helpful?

Solution

At the very start of your script, use console.time('Some_Name_Here');, and then use console.timeEnd('Some_Name_Here'); wherever the script finishes its execution.

It's a quick, native functionality of Node.js, and prevents you from having to initialize a new Date object.

Here's some short documentation on the console.time() method: http://nodejs.org/api/stdio.html#stdio_console_time_label.

OTHER TIPS

You could do the time start/end timing method.

At the beginning of your main script you grab the time.

var start = Date.now();

process.on("exit", function() {
  var end = Date.now();
  console.log("Time taken: %ds", (end - start)/1000);
});

// all you code...
// more code...
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top