Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the better way to get the Node.js app total time execution?

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.

like image 676
tetri Avatar asked Jul 19 '13 20:07

tetri


People also ask

Is NodeJS real-time data intensive?

Node. js uses non-blocking, event driven I/O to offer efficiency and remain lightweight in terms of in-memory usage to data intensive real time web applications that run in various distributed environments or devices.

Is NodeJS good for real-time applications?

The standard library comes with asynchronous commands and helps with non-blocking paradigms. Node JS is an excellent choice for developers in real-time applications and has proven to be successful in similar use-cases across the industry.


1 Answers

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.

like image 116
Shrey Gupta Avatar answered Sep 26 '22 16:09

Shrey Gupta