От: | rFLY | ||
Дата: | 11.06.24 21:24 | ||
Оценка: | 25 (2) |
constructor()
{
this.Value = BaseClass.Counter++;
}
constructor()
{
this.Value = this.constructor.Counter++;
}
4999999950000000
1: 104.80000019073486
4999999950000000
2: 101.09999990463257
class BaseClass
{
constructor()
{
this.Value = this.constructor.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();
let sum = 0;
for (let i = 0; i < 100_000_000; i++)
{
let obj = new BaseClass();
let val = obj.TestMethod();
sum += val;
}
console.log(sum);
var time = performance.now() - watch;
console.log(`2: ${time}`);
}