Date, tf.time, performance
Date can be used to indicate the time taken to execute a function.
a = new Date().getTime()
// execute function f()
b = new Date().getTime()
// executed time in milliseconds b - a
The caveat is that this function is affected by the time of the system
tf.Time() give more details regarding the time taken to execute a function. It outputs the time taken by the backend to read the data and the wall time. It can be useful to know what tfjs is doing internally.
tf.time(() => f() ) // execute f as callback
Using performance
a = performance.now()
// execute f()
b = performance.now()
// executed time in milliseconds b - a
It has been implemented to evaluate the execution timing. Unlike Date, it is independent of the system clock.
Measure execution time
Coming to the code of the question, it is unclear what performance is measured. If the goal is to measured the overall performance of the code,
var w = new Date();
var r = w.getTime();
for (var q = 0; q<29; q++){
var x = tf.concat([new_I[q++],new_I[q++], new_I[q++],new_I[q]]);
var hr_image = await pretrainedModel.execute(x);
}
var y = new Date();
var u = y.getTime();
console.log(u-r);
If the goal is to measure the time taken for each prediction
for (var q = 0; q<29; q++){
var w = new Date();
var r = w.getTime();
var x = tf.concat([new_I[q++],new_I[q++], new_I[q++],new_I[q]]);
var hr_image = await pretrainedModel.execute(x);
var y = new Date();
var u = y.getTime();
console.log(u-r);
}
But as explain above using performance.now() is better than using Date