От: | Codealot | ||
Дата: | 08.06.24 18:27 | ||
Оценка: | 6 (1) |
4999999950000000
1: 320.7000000476837
4999999950000000
2: 1602.199999988079
class BaseClass
{
constructor()
{
this.Value = BaseClass.Counter++;
}
TestMethod()
{
return this.Value;
}
static Counter = 0;
}
var func = function()
{
var sum = 0;
for (var i = 0; i < 100_000_000; i++)
{
var obj = new BaseClass();
var val = obj.TestMethod();
sum += val;
}
console.log(sum);
};
{
var watch = performance.now();
func();
var time = performance.now() - watch;
console.log(`1: ${time}`);
}
BaseClass.Counter = 0;
{
var watch = performance.now();
var sum = 0;
for (var i = 0; i < 100_000_000; i++)
{
var obj = new BaseClass();
var val = obj.TestMethod();
sum += val;
}
console.log(sum);
var time = performance.now() - watch;
console.log(`1: ${time}`);
}