Author Topic: Efficiency Test  (Read 606 times)

0 Members and 1 Guest are viewing this topic.

Offline Hacktank

  • Camper
  • ***
  • Posts: 462
  • Soldat Scripter
    • HTZRPG
Efficiency Test
« on: February 22, 2010, 10:13:10 pm »
Hello guys, I need help testing the efficiency of two functions that do the same thing but in different ways. I would do it, but i have never gotten formatdate to behave and i know some of you have working time calculation functions.

The function is SetPlayerHealth. From the name you can tell it sets the players health and vest to a specific number. One strips the vest off, does the health and fixes the vest to the required amount. The other does both at the same time. Which is better?

Method One
Code: [Select]
procedure SetPlayerHealth(ID: byte; Health,Vest: integer; RecalcHealth: boolean);
var chealth,cvest: integer;
begin
chealth := getplayerstat(ID,'health');
cvest := getplayerstat(ID,'vest');
if (chealth=health) AND (cvest=vest) then exit;
if chealth = 0 then dodamage(ID,1000);
while(cvest > 0) do begin
//sbot[ID].flatdamage := sbot[ID].flatdamage + 1; Mod specific use
dodamage(ID,2);
cvest := cvest - 1;
end;
if recalchealth then sbot[ID].health := round(health*(inttofloat(sbot[ID].maxhealth+player[ID].extrahp)/150));
//sbot[ID].flatdamage := sbot[ID].flatdamage + 1; Mod specific use
dodamage(ID,chealth-health);
if vest = 0 then exit;
givebonus(ID,3);
cvest := 100;
while(cvest > vest) do begin
//sbot[ID].flatdamage := sbot[ID].flatdamage + 1; Mod specific use
dodamage(ID,2);
cvest := cvest - 1;
end;
end;

Method Two
Code: [Select]
procedure SetPlayerHealth(ID: byte; Health,Vest: integer; RecalcHealth: boolean);
var chealth,cvest,delta: integer;
begin
chealth := getplayerstat(ID,'health');
cvest := getplayerstat(ID,'vest');
if recalchealth then sbot[ID].health := round(health*(inttofloat(sbot[ID].maxhealth+player[ID].extrahp)/150));
if (chealth=health) AND (cvest=vest) then exit;
if chealth = 0 then dodamage(ID,1000);
if vest = 0 then begin
while(cvest > 0) do begin
//sbot[ID].flatdamage := sbot[ID].flatdamage + 1;
dodamage(ID,2);
cvest := cvest - 1;
end;
//sbot[ID].flatdamage := sbot[ID].flatdamage + 1;
dodamage(ID,chealth-health);
exit;
end else begin
if cvest = 0 then begin
givebonus(ID,3);
cvest := 100;
end;
while(chealth <> health) do begin
//sbot[ID].flatdamage := sbot[ID].flatdamage + 1;
if chealth < health then delta := -1 else delta := 1;
dodamage(ID,3*delta);
chealth := chealth - delta;
cvest := wrapvalue(cvest - delta,0,100,true);
if cvest = 0 then begin
givebonus(ID,3);
cvest := 100;
end;
if cvest <> vest then begin
//sbot[ID].flatdamage := sbot[ID].flatdamage + 1;
if cvest < vest then delta := -1 else delta := 1;
dodamage(ID,2*delta);
cvest := cvest - delta;
end;
end;
while(cvest <> vest) do begin
//sbot[ID].flatdamage := sbot[ID].flatdamage + 1;
if cvest < vest then delta := -1 else delta := 1;
dodamage(ID,2*delta);
cvest := cvest - delta;
end;
exit;
end;
givebonus(ID,3);
cvest := 100;
while(cvest > vest) do begin
//sbot[ID].flatdamage := sbot[ID].flatdamage + 1;
dodamage(ID,2);
cvest := cvest - 1;
end;
end;

Thank You for your time.
« Last Edit: February 22, 2010, 10:15:41 pm by Hacktank »


Offline dnmr

  • Camper
  • ***
  • Posts: 315
  • emotionally handicapped
Re: Efficiency Test
« Reply #1 on: February 23, 2010, 12:19:07 am »
why not use microtime?

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Re: Efficiency Test
« Reply #2 on: February 23, 2010, 08:41:03 am »
For the current non-beta server version, I did make a thing that uses FormatDate to output a numeric result of number of milliseconds, but I don't have access to it right now. If I remember tonight, I'll post it.
It would be better to simply download and use the beta server version, which supports microtime function, as dnmr has mentioned.