Tensorflow.js tf.time() Function
Last Updated :
08 Jul, 2021
Tensorflow.js is an open-source library that was developed by Google for running machine learning models as well as deep learning neural networks in the browser or node environment.
The tf.time() function is used to execute the stated function, f() as well as return a promise in order that determines along with timing details. The resultant is an object along with the properties like Wall execution time, Kernel execution time, excluding transfer of data. In case the WebGL backend is used as well as query ticker is unavailable then this method will throw an error object. Moreover, the WebGL backend will provide the further properties like uploadWaitMs i.e. blocking time of CPU on texture uploads, and downloadWaitMs i.e. blocking time of CPU on texture downloads.
Syntax:
tf.time(f)
Parameters: This function accepts a single parameter as mentioned below:
- f: It is the stated function to execute as well as time.
Return Value: It returns a Promise of TimingInfo.
Example 1:
Javascript
import * as tf from "@tensorflow/tfjs"
const p = tf.truncatedNormal([10, 10]);
const tm = await tf.time(() => p.dot(p));
console.log(`Kernel execution time:
${tm.kernelMs}, Wall execution time: ${tm.wallMs}`
);
|
Output:
Kernel execution time: 0.048498, Wall execution time: 85.19999992847443
Example 2:
Javascript
import * as tf from "@tensorflow/tfjs"
const t = await tf.time(() => tf.square(tf.ones([15, 21])));
console.log(`uploadWaitMs: ${t.uploadWaitMs},
downloadWaitMs: ${t.downloadWaitMs}`);
|
Output:
uploadWaitMs: 1.100000023841858, downloadWaitMs: 0
Reference: https://js.tensorflow.org/api/latest/#time
Share your thoughts in the comments
Please Login to comment...