Author Topic: Efficient Scripting? [solved, use explode]  (Read 932 times)

0 Members and 1 Guest are viewing this topic.

Offline ExHunter

  • Inactive Soldat Developer
  • Soldier
  • ******
  • Posts: 154
  • Speedy go!
Efficient Scripting? [solved, use explode]
« on: June 02, 2011, 07:19:39 am »
I'm one of these persons, those scripted not really efficient. So it's like: I didn't payed attention how I script something, as long as this works. So but now I need to find out, how I can improve them more and more by some small changes, like: If a part of a script needs 2 seconds and I could reduce the calculation time to 1,5 seconds so it would be awesome. Does someone know a way for this?

Well and another thing that I wanted to introduce with this Topic: A discussion about my "Version" of explode ;) - I call it CSplit:

Code: [Select]
function CSplit(Source: string; const Cut: string): array of string;
var
  rep: integer;
begin
  repeat
    SetArrayLength(Result, rep + 1);
    Result[rep] := GetPiece(Source,Cut,rep);
    inc(rep,1);
  until (Result[rep-1] = NIL);
  SetArrayLength(Result, rep - 1);
end;

It uses some less variables than explode, but i'm not sure of the speed of this function. But it works exactly like explode. Maybe someone could compare those 2 functions... I'm using a Server where REALLY much datas are loaded, so every single improvement could help me (and for sure other people also). :D

ExHunter

EDIT: This seems to be a improvement:

Code: [Select]
function CSplit(Source: string; const Cut: string): array of string;
var
  rep: integer;
begin
  rep := -1;
  repeat
    inc(rep,1);
    SetArrayLength(Result, rep + 1);
    Result[rep] := GetPiece(Source,Cut,rep);
  until (Result[rep] = NIL);
  SetArrayLength(Result, rep);
end;
« Last Edit: June 02, 2011, 10:11:54 am by ExHunter »

Offline dnmr

  • Camper
  • ***
  • Posts: 315
  • emotionally handicapped
Re: Efficient Scripting?
« Reply #1 on: June 02, 2011, 08:56:59 am »
afair getpiece calls a native explode, and then returns one element of the array. So the computer is doing the same job n times (where n is the number of pieces to split). Run a benchmark though, i'm curious about how much faster/slower it actually is

Offline ExHunter

  • Inactive Soldat Developer
  • Soldier
  • ******
  • Posts: 154
  • Speedy go!
Re: Efficient Scripting?
« Reply #2 on: June 02, 2011, 10:07:03 am »
You were right. Did tested it with a script. FormatDate('zzz') for ms before this function and after it:

My Sort: 0.874 seconds needed
explode (the new one): 0.012 seconds needed

thats just.. LOL

I think i won't use GetPiece anymore for such a thing o_o

Edit:

XSplit: 0.117 seconds (just tested)

Edit 2:

Added the Script for it.
« Last Edit: June 02, 2011, 10:19:34 am by ExHunter »