Author Topic: [SC3] function GetPiece(Str, Reg: string; Number: byte): string;  (Read 3483 times)

0 Members and 1 Guest are viewing this topic.

Offline kicikici

  • Soldier
  • **
  • Posts: 180
[SC3] function GetPiece(Str, Reg: string; Number: byte): string;
« on: December 04, 2017, 03:39:50 pm »
See attachment:
Code: [Select]
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
GetPiece2: https://forums.soldat.pl/index.php?topic=44408.0

Code: [Select]
(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
« Last Edit: December 04, 2017, 03:52:04 pm by kicikici »
Classic banana

Offline soldat-game

  • Camper
  • ***
  • Posts: 407
Re: [SC3] function GetPiece(Str, Reg: string; Number: byte): string;
« Reply #1 on: December 05, 2017, 04:51:02 pm »
Nice, normal getpiece (sc2) be 0.5 ur be 0.9. (400 ms slowest) but very good

Offline soldat-game

  • Camper
  • ***
  • Posts: 407
Re: [SC3] function GetPiece(Str, Reg: string; Number: byte): string;
« Reply #2 on: December 11, 2017, 09:30:15 am »
Wooow im must test it

Offline kicikici

  • Soldier
  • **
  • Posts: 180
Re: [SC3] function GetPiece(Str, Reg: string; Number: byte): string;
« Reply #3 on: December 11, 2017, 03:41:39 pm »
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.
Classic banana

Offline Savage

  • Soldier
  • **
  • Posts: 155
Re: [SC3] function GetPiece(Str, Reg: string; Number: byte): string;
« Reply #4 on: December 11, 2017, 07:03:21 pm »
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
« Last Edit: December 11, 2017, 07:14:30 pm by Savage »

Offline soldat-game

  • Camper
  • ***
  • Posts: 407
Re: [SC3] function GetPiece(Str, Reg: string; Number: byte): string;
« Reply #5 on: July 02, 2018, 12:43:43 pm »
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);

Offline soldat-game

  • Camper
  • ***
  • Posts: 407
Re: [SC3] function GetPiece(Str, Reg: string; Number: byte): string;
« Reply #6 on: July 05, 2018, 06:00:26 am »
Code: [Select]
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