Thursday, September 4, 2025
HomeLanguagesJavascriptTensorflow.js tf.profile() Function

Tensorflow.js tf.profile() Function

Tensorflow.js is an open-source library developed by Google for running machine learning models and deep learning neural networks in the browser or node environment. It also helps the developers to develop ML models in JavaScript language and can use ML directly in the browser or in Node.js.

The tf.profile() function is used for executing the provided function and the function returns a Promise that resolves with information about its memory use.

Syntax:

tf.profile(f);

Parameters:

  • f: It is a callback function.

Return Value: It returns Promise.

Example:

Javascript




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Initializing tensor and 
// Using .profile() function 
let geekProfile =
   await tf.profile(function (){
   let geek1 = tf.tensor2d([[1, 2, 3], [4, 5, 6]]);
   geek1.square();
   return geek1;
});
  
// Printing the result of returned Promise
console.log("peakBytes: ")
console.log(geekProfile.peakBytes);
console.log("kernelName: ");
console.log(geekProfile.kernelNames);


Output:

peakBytes: 
48
kernelName: 
Square

Example 2:

Javascript




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Initializing tensor and 
// Using .profile() function 
let geekProfile =
   await tf.profile(function (){
   let geek2 = tf.tensor4d([[[[7], [11]], [[13], [34]]]]);
   return geek2;
});
  
// Printing the result of returned Promise
console.log("newBytes ")
console.log(geekProfile.newBytes);


Output:

newBytes 
16

Reference: https://js.tensorflow.org/api/latest/#profile

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32260 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6625 POSTS0 COMMENTS
Nicole Veronica
11795 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11855 POSTS0 COMMENTS
Shaida Kate Naidoo
6747 POSTS0 COMMENTS
Ted Musemwa
7023 POSTS0 COMMENTS
Thapelo Manthata
6694 POSTS0 COMMENTS
Umr Jansen
6714 POSTS0 COMMENTS