Hi, I recently had 2 questions that I wanted to discuss here on the forum.
First Doubt: The efficiency of a script
when we develop systems, we realize that there are several different ways to write the system and get the expected result, however there are more efficient ways that cause less impact to the server.
I would like to know, what would be the best way to qualify the efficiency of a script. Would the script execution time be a valid parameter for this type of test?
Second Doubt:?When to use or not to use the data directly from the bank
In this second question I would like to know the best way to work with MySQL. For example, in a system that makes queries, additions and updates the best and most efficient way would be to load this sql data into variables, manipulate those variables and then update the data sql, or do all the manipulations directly in the database?
Can anyone help with these doubts?
I recommend you to use SQLite instead of MySQL. Overall, it?s much easier to use, and faster than mysql. You don?t need anything basically for it, just a server and an include.
The first topic is not an easy one to talk about. There are lots of factors that need to be taken in. Not everyone understands efficiency the same way. For someone efficiency can be writing code in a clear way and having no trouble of editing it. For some it's about the functionality that the code has to offer. And of course, for some, it's all about the speed just like you mentioned. If you checked some releases that have to deal with quite a bit of data you will see speed comparisons with their release and others. Even when lots of very experienced people say that speed is not everything you still see those same people comparing speeds.
destiezk posted a link of backup sa-mp forum where I think you should be able to find some information on what you want to find answers for: https://sampforumarchive.com/forum.sa-mp.com/index.html
But I think we can all agree that optimizing your code is one of those things that makes the code efficient. So go on and search that forum for optimization posts and threads.
2021-03-01, 01:37 PM
(This post was last modified: 2021-03-01, 01:40 PM by Marllun.)
1 -
Code: CMD:speedtest(playerid) {
? ? new var, string[20];
? ? var = GetTickCount();
? ? for(new i; i < 100000; i) {//it has to be several times because these functions run very fast, to be more precise I increase the number of times
? ? ? ? SendClientMessage(playerid, -1, "Bem vindo ao Brasil.");
? ? }
? ? printf("Time taken to run SendClientMessage %d milliseconds", GetTickCount() - var);
? ? var = GetTickCount();
? ? for(new i; i < 100000; i) {
? ? ? ? format(string, sizeof(string), "Bem vindo ao Brasil");
? ? ? ? SendClientMessage(playerid, -1, string);
? ? }
? ? printf("Time taken to run SendClientMessage with format %d milliseconds", GetTickCount() - var);
? ? return 1;
}
Time taken to run SendClientMessage 81 milliseconds
Time taken to run SendClientMessage with format 117 milliseconds
OBS:I recommend running the script that you would like to test on a server with nothing, and one test at a time, anything in the background can disrupt the result.
2 - I recommend you use your gamemode variables to save, save the information only when the player leaves your server. And again, use mysql_tquery
2? Another tip, do not spend your time saving string on your server, but avoid use giant strings without any need.
Code: Discord: Marllun#6297
Location: Belgrade, Serbia
(2021-02-28, 11:31 PM)destiezk Wrote: I recommend you to use SQLite instead of MySQL. Overall, it?s much easier to use, and faster than mysql. You don?t need anything basically for it, just a server and an include.
So you're saying that SQLite, who themselves are claiming that they're slower than MySQL and that they're not trying to compete with RDBMS but other file-based solutions like INI arefaster than Mysql?
Using Pawn.CMD?
If you're doing so, this is the very first sign that you absolutely shouldn't utilize your all powerful P-Code knowledge in any of the scripting discussion topics.
(2021-03-01, 02:41 PM)Pinch Wrote: (2021-02-28, 11:31 PM)destiezk Wrote: I recommend you to use SQLite instead of MySQL. Overall, it?s much easier to use, and faster than mysql. You don?t need anything basically for it, just a server and an include.
So you're saying that SQLite, who themselves are claiming that they're slower than MySQL and that they're not trying to compete with RDBMS but other file-based solutions like INI arefaster than Mysql?
I'm sorry my bad, my informations were wrong about SQLite then.
Thanks for the personal help with my personal questions, I am taking each opinion into consideration!
Optimisation is hard, but profiling is even harder. You can run micro-benchmarks like Marllun posted, but they are basically useless most of the time. The real trick is finding which parts of your code are actually slow, and for that you need the profiler plugin. Once you've narrowed down where the majority of the time is spent (don't try guess what is slow, because fast code called a lot is more important to optimise than slow code called infrequently) you can work on improving it. For that, the most important thing is algorithms - improve HOW the result is achieved, don't just try shave a few microseconds off the code. For example a poorly coded slow version of quicksort is still better than the most optimised version of bubblesort, because while the code itself may be worse, the algorithm is just so much better.
|