Official Soldat Forums
Server Talk => Scripting Releases => Topic started by: kicikici on December 04, 2017, 03:39:50 pm
-
See attachment:
gp.pas
Comparison of executon time to another implementations which can be found on forum:
GetWord: https://forums.soldat.pl/index.php?topic=44988.0 (https://forums.soldat.pl/index.php?topic=44988.0)
GetPiece2: https://forums.soldat.pl/index.php?topic=44408.0 (https://forums.soldat.pl/index.php?topic=44408.0)
(21:31:02) /test getpiece (x.x.x.x)
(21:31:02) 50000 x GetPiece('jedd66f jj92jhfjdh hmmnkjdkjf kjk1ssxjkj1 3lk4l3111 3335', ' ', 3); = 00:00:00,507
(21:31:06) /test getpiece2 (x.x.x.x)
(21:31:13) 50000 x GetPiece2('jedd66f jj92jhfjdh hmmnkjdkjf kjk1ssxjkj1 3lk4l3111 3335', ' ', 3); = 00:00:05,986
(21:31:13) /test getword (x.x.x.x)
(21:31:18) 50000 x GetWord('jedd66f jj92jhfjdh hmmnkjdkjf kjk1ssxjkj1 3lk4l3111 3335', 3); = 00:00:05,030
-
Nice, normal getpiece (sc2) be 0.5 ur be 0.9. (400 ms slowest) but very good
-
Wooow im must test it
-
Lil bit faster :P
Sure, it will be faster because you have removed code responsible for freeing allocated memory used by temporary TStringList array. It will cause memory leak. Futhermore, you have separated SplitRegExpr function outside of "try except" clause, which can also throw exception. So, it is basically bad approach. To sum up, your modifications are destroyably wrong.
-
U're probably right, thought it's freed automatically like local variable. I had to find some explanation, maybe this one can confirm that http://www.delphibasics.co.uk/Article.asp?Name=Memory
-
I will add more u try split example game.mp3 u must use "\" to be able to use the dot character in the expression.
example GetPiece(temp,'\.',0);
-
function GetPiece(Str, Reg: string; Number: byte): string;
var
Res: TStringList;
begin
try
Res := File.CreateStringList;
SplitRegExpr(QuoteRegExprMetaChars(Reg), Str, Res);
Result:=Res.Strings[Number];
except
Result:='';
finally
Res.Free;
end;
end;
Fix