• Node.js Video Tutorials

NodeJS - console.profileEnd() Method



The Node.js console.profileEnd() method will stop the JavaScript CPU profiling session of the profile which has been called previously and print the report to the profiles panel of the inspector. In simple terms, it stops the recording of a profile that was previously started with the console.profile() method.

Syntax

Following is the syntax of the Node.js console.profileEnd() method −

console.profileEnd([label])

Parameters

  • label − We can pass the label for the profile with a name and the input name should be a string. And this passed label should be the same as in the console.profile() method to close the particular profile.

Return value

This method returns nothing instead; it will end the JavaScript CPU profile in the inspector.

Example

In this example,

  • We are calling the Node.js console.profile() method by passing a name to the label parameter.

  • Then we have written some lines of code.

  • Then we are ending the previously called profile with the console.profileEnd() method with the same label in the console.profile() method.

console.profile("one");
	var a = 5, b = 5;
	var c = a * b;
	console.log(c);
console.profileEnd("one");

Output

25

To understand better execute the above code in the browser's console. Following is the output, if we execute it in the browser's console.

As we can see in the figure below, the console.profileEnd() method has a profile name and it matches the name of the profile is started, then that profile will be stopped.

console_profile_end

Example

In this example,

  • We are calling the Node.js console.profile() method by passing a name to the label parameter.

  • Then we are performing an operation for adding two numbers.

  • Then we are ending the previously called profile with the console.profileEnd() method with different label

console.profile("one");
	var a = 5, b = 5;
	var c = a + b;
	console.log(c);
console.profileEnd("two");

Output

10

To understand better execute the above code in the browser's console. Following is the output, if we execute it in the browser's console.

As we can see in the figure below, the console.profileEnd() method has a profile name and it is not matching with name of the profile is started, so no changes will be made.

profile_end_method

Example

In this example,

  • We are calling the Node.js console.profile() method with three times with different label names.

  • Then we are performing an operation for adding an element to the array.

  • Then we are ending the previously called profile with the console.profileEnd() method without passing any label of a profile being recorded.

console.profile("One");
console.profile("Two");
console.profile("Three");
	var array = ["Blue", "Black", "Purple"];
	array.push("Yellow");
	console.log(array);
console.profileEnd();

Output

[ 'Blue', 'Black', 'Purple', 'Yellow' ]

To understand better execute the above code in the browser's console. Following is the output, if we execute it in the browser's console.

As we can see the figure below figure. The console.profileEnd() method is called without any passed profile name so, the most recently started profile will be stopped.

profile_stopped

Example

In this example,

  • We are calling the Node.js console.profile() method without passing any name to the label parameter.

  • Then we have written some lines of code.

  • Then we are ending the previously called profile with the console.profileEnd() method.

console.profile();
	for (var i = 0; i < 3; i++) {
		console.log(i);
	}
console.profileEnd();

Output

0
1
2

To understand better execute the above code in the browser's console. Following is the output, if we execute it in the browser's console.

As we can see from the figure below, if we do not pass any label to the method, by default, it will name the profile as 'Profile 1' and so on.

profile1
nodejs_console_module.htm
Advertisements