BTXT - Fast and Easy Text Processor -
BigETI - 21.11.2011
This time I want to introduce you an include, where you can use normal text inputs as commands which will be performed faster than using strcmp checks in OnPlayerText.
I've created this include because my heart bleeds if some peoples starts to script text string checks in OnPlayerText by using strcmp checks.
Example: http://pastebin.com/3sMRVaMY
Anyways this include is very easy to use, is not case sensitive, is very fast and can detect strings for params array.
How to use this include?
It's quite easy to use. (Idea from ZCMD)
You can use
pawn Код:
TXT:hello(playerid, params[])
or
pawn Код:
TEXT:hello(playerid, params[])
or (not recommend)
pawn Код:
forward txt_hello(playerid, params[]);
public txt_hello(playerid, params[])
//...
Код:
TXT:hello(playerid, params[])
Callback start:
Text string:
Player ID
Params string:
Example:
pawn Код:
TXT:test(playerid, params[])
{
new str[128];
format(str, 128, "You have wrote 'test' with following params: '%s'", params);
SendClientMessage(playerid, 0xFF0000FF, str);
return 0;
}
Even you can use the sscanf include/plugin (from ******) to parse strings to variables from params array.
https://sampforum.blast.hk/showthread.php?tid=120356
About returning values in txt_
If the callback exists, so returning 0 will deny executing TXT_OnPlayerText (muting) otherwise TXT_OnPlayerText will be also called!
Benchmark Tests
Results (Looping 10000 times through):
Код:
BTXT without params: 60-65 ms
BTXT with params (large params string): 252-263 ms
strcmp methode without params: 19037 ms
strcmp methode with params (same large params string as in BTXT check): 108984 ms
As we can see that my include is still faster than using strcmp checks in OnPlayerText.
Benchmark scripts:
http://solidfiles.com/d/8fc89eca14/
IF you find any another text processors, so please reply on this topic!
Credits:- Idea from ZCMD include (ZeeX)
- Hooking methode by ******
- Myself for creating this include
Downloads:
Download btxt.inc from Solidfiles
Download btxt.inc from Pastebin
Regards: BigETI
Re: BTXT - Fast and Easy Text Processor -
Speed - 21.11.2011
nice
Re: BTXT - Fast and Easy Text Processor -
fiki574 - 21.11.2011
Nice on!
Re: BTXT - Fast and Easy Text Processor -
FireCat - 21.11.2011
Looks cool, benchmark it with zcmd and ycmd please.
AW: Re: BTXT - Fast and Easy Text Processor -
BigETI - 21.11.2011
Thanks
Quote:
Originally Posted by FireCat
Looks cool, benchmark it with zcmd and ycmd please.
|
It has nothing to do with command processors..
Re: BTXT - Fast and Easy Text Processor -
System64 - 21.11.2011
hah nice work dude
You have useful includes
AW: BTXT - Fast and Easy Text Processor -
BigETI - 21.11.2011
Thanks, I appreciate it System64
Re: BTXT - Fast and Easy Text Processor -
Finn - 21.11.2011
This doesn't even work?
TIMING FOR STRCMP:
Код:
TIME: 1059 BOOYAKA: 1000000
TIMING FOR BTXT:
Booyaka is zero, which means the whole function wasn't even called.
Here's my testing script:
pawn Код:
#include <a_samp>
new booyakabooyaka;
#include <btxt>
TEXT:hello(playerid, params[])
{
booyakabooyaka++;
return 1;
}
public OnPlayerText(playerid, text[])
{
return 1;
}
/*public OnPlayerText(playerid, text[])
{
if(!strcmp("hello", text, true))
{
booyakabooyaka++;
}
return 1;
}*/
main()
{
print("\n----------------------------------");
print(" Bare Script\n");
print("----------------------------------\n");
return 1;
}
public OnGameModeInit()
{
new check1 = GetTickCount();
for(new i; i < 1000000; i++)
{
OnPlayerText(0, "hello");
}
new check2 = GetTickCount();
printf("TIME: %d BOOYAKA: %d", check2-check1, booyakabooyaka);
return 1;
}
AW: Re: BTXT - Fast and Easy Text Processor -
BigETI - 21.11.2011
Quote:
Originally Posted by Finn
This doesn't even work?
TIMING FOR STRCMP:
Код:
[20:21:02] TIME: 1059 BOOYAKA: 1000000
TIMING FOR BTXT:
Booyaka is zero, which means the whole function wasn't even called.
Код:
[20:22:36] TIME: 44 BOOYAKA: 0
Here's my testing script:
pawn Код:
#include <a_samp> new booyakabooyaka;
#include <btxt> TEXT:hello(playerid, params[]) { booyakabooyaka++; return 1; }
public OnPlayerText(playerid, text[]) { return 1; }
/*public OnPlayerText(playerid, text[]) { if(!strcmp("hello", text, true)) { booyakabooyaka++; } return 1; }*/
main() { print("\n----------------------------------"); print(" Bare Script\n"); print("----------------------------------\n"); return 1; }
public OnGameModeInit() { new check1 = GetTickCount();
for(new i; i < 1000000; i++) { OnPlayerText(0, "hello"); }
new check2 = GetTickCount();
printf("TIME: %d BOOYAKA: %d", check2-check1, booyakabooyaka); return 1; }
|
You are doing it wrong. You can't use
pawn Код:
OnPlayerText(0, "hello");
as function.
Use
pawn Код:
CallLocalFunction("OnPlayerText", "ds", 0, "hello");
instead.
Anyways you are free to use my benchmark scripts which are downloadable from a file hoster and are posted in the main post.
Quote:
Originally Posted by Kerlan
:/ video??
|
Of?
Re: AW: Re: BTXT - Fast and Easy Text Processor -
FireCat - 21.11.2011
Quote:
Originally Posted by BigETI
Thanks
It has nothing to do with command processors..
|
Lol my fail. Sorry
Re: AW: Re: BTXT - Fast and Easy Text Processor -
Finn - 22.11.2011
Quote:
Originally Posted by BigETI
You are doing it wrong. You can't use
Code:
OnPlayerText(0, "hello");
as function.
Use
Code:
CallLocalFunction("OnPlayerText", "ds", 0, "hello");
instead.
Anyways you are free to use my benchmark scripts which are downloadable from a file hoster and are posted in the main post.
|
Okay, yeah it worked now and seems to be
slower than simply having strcmp:
BTXT:
Code:
TIME: 6709 BOOYAKA: 1000000
strcmp:
Code:
TIME: 1665 BOOYAKA: 1000000
Re: AW: Re: BTXT - Fast and Easy Text Processor -
KoczkaHUN - 22.11.2011
Quote:
Originally Posted by Finn
Okay, yeah it worked now and seems to be slower than simply having strcmp:
BTXT:
Code:
TIME: 6709 BOOYAKA: 1000000
strcmp:
Code:
TIME: 1665 BOOYAKA: 1000000
|
It is not about ONE check, it is about a BUNCH OF text checks.
Re: BTXT - Fast and Easy Text Processor -
TheArcher - 22.11.2011
Pretty nice idea, could you put the benchmark test on pastebin too please?
Re: BTXT - Fast and Easy Text Processor -
marwan - 22.11.2011
Good job keep it up
Re: AW: Re: BTXT - Fast and Easy Text Processor -
Finn - 23.11.2011
Quote:
Originally Posted by KoczkaHUN
It is not about ONE check, it is about a BUNCH OF text checks.
|
I had 1 million checks, how much more does it need?
Re: BTXT - Fast and Easy Text Processor -
Biesmen - 23.11.2011
That is why I think making more command processors is useless, since there are many and very good and fast ones, which can't be beated according to the speed (well, it can, but not really.. easy).
ZCMD and y_cmds is simply the best ones, which will never be replaced. That's why I think this include was a waste of your time. However, nice try and nicely done.
Re: BTXT - Fast and Easy Text Processor -
System64 - 23.11.2011
Quote:
Originally Posted by Biesmen
That is why I think making more command processors is useless, since there are many and very good and fast ones, which can't be beated according to the speed (well, it can, but not really.. easy).
ZCMD and y_cmds is simply the best ones, which will never be replaced. That's why I think this include was a waste of your time. However, nice try and nicely done.
|
do you know what you are talking about?
You talk about command processor and this include
is not command processor
Re: AW: Re: BTXT - Fast and Easy Text Processor -
wups - 23.11.2011
Quote:
Originally Posted by Finn
I had 1 million checks, how much more does it need?
|
He means that you need lots of different texts, for it to be faster.
For example,
if you have one command, then strcmp would be faster than zcmd!
AW: Re: BTXT - Fast and Easy Text Processor -
BigETI - 23.11.2011
Quote:
Originally Posted by TheArcher
Pretty nice idea, could you put the benchmark test on pastebin too please?
|
Pastebin does not accept the size of my benchmark scripts.
So you're free to download it from solidfiles.
Quote:
Originally Posted by Biesmen
That is why I think making more command processors is useless, since there are many and very good and fast ones, which can't be beated according to the speed (well, it can, but not really.. easy).
ZCMD and y_cmds is simply the best ones, which will never be replaced. That's why I think this include was a waste of your time. However, nice try and nicely done.
|
So learn reading the topic. This include has nothing to do with commands.
Quote:
Originally Posted by Finn
Okay, yeah it worked now and seems to be slower than simply having strcmp:
BTXT:
Code:
TIME: 6709 BOOYAKA: 1000000
strcmp:
Code:
TIME: 1665 BOOYAKA: 1000000
|
You have probably done something wrong.
Show me your benchmark script.
Re: AW: Re: BTXT - Fast and Easy Text Processor -
Finn - 23.11.2011
Quote:
Originally Posted by wups
He means that you need lots of different texts, for it to be faster.
For example,
if you have one command, then strcmp would be faster than zcmd!
|
Edit: Andre is right (post below)
You are right, when I tried the same with 10 texts ("hello0".."hello9"), the timings were almost the same:
strcmp:
Code:
TIME: 70570 BOOYAKA: 10000000
BTXT:
Code:
TIME: 69182 BOOYAKA: 10000000
--
Quote:
Originally Posted by BigETI
You have probably done something wrong.
Show me your benchmark script.
|
It's in the first page, I already posted it, but here it is again:
Code:
#include <a_samp>
new booyakabooyaka;
#include <btxt>
TEXT:hello0(playerid, params[])
{
booyakabooyaka++;
return 1;
}
public OnPlayerText(playerid, text[])
{
return 1;
}
/*public OnPlayerText(playerid, text[])
{
if(!strcmp("hello0", text, true))
{
booyakabooyaka++;
}
return 1;
}*/
main()
{
print("\n----------------------------------");
print(" Bare Script\n");
print("----------------------------------\n");
return 1;
}
public OnGameModeInit()
{
new check1 = GetTickCount();
for(new i; i < 1000000; i++)
{
CallLocalFunction("OnPlayerText", "ds", 0, "hello0");
}
new check2 = GetTickCount();
printf("TIME: %d BOOYAKA: %d", check2-check1, booyakabooyaka);
return 1;
}