[Pas2js] sluggish Trunc

warleyalex warleyalex at yahoo.com.br
Mon Aug 12 01:06:32 CEST 2019


I've made a little test 4x using this code in both pas2js and dwscript/sms:

-------
  try
    for I := 0 to 999999999 do
    begin
      Aux := Trunc(I / 2);
    end;
  finally
    console.log(Aux);
  end;   
-------


======+|================
pas2js => time elapsed

9.78179999999702 secs
8.77317499998026 secs
8.65989000000991 secs
8.4647399999667 secs

pas2js => time elapsed

1.9587950001005083 secs
1.3956900000339374 secs
1.3954049999592826 secs
1.3983049999224022 secs

The sluggish is the pas2js Trunc function, if I replace to this dwscript
version, I have similar results!

//-----------dwscript----------------------------
this.Trunc = function(v) { return (v>=0)?Math.floor(v):Math.ceil(v) };

//-------pas2js ---------------
  this.Trunc = function (A) {
    if (!Math.trunc) {
      Math.trunc = function(v) {
        v = +v;
        if (!isFinite(v)) return v;
        return (v - v % 1) || (v < 0 ? -0 : v === 0 ? v : 0);
      };
    }
    $mod.Trunc = Math.trunc;
    return Math.trunc(A);
  };
-------------------------------




--
Sent from: http://pas2js.38893.n8.nabble.com/


More information about the Pas2js mailing list