![]() |
Efficiency!
Debate between Kuji and I :Which method is more efficient? My example first then his.
PHP Code:
Compared to: PHP Code:
Of course a possibility might be to switch the clientside commands. If not there, check if the command is in an array of serverside commands: if so, serverside. Else displays an error message :) This may server only make the script look nicer and may have no benefits in efficiency |
I like Example 1 more, and Id say its the most efficient way to do it.
|
I think example 1 looks more orginazed, and most efficient.
|
In all technicality, example 2 is the most efficient in that it is not evaluating everything that is passed from ChatBar. However, it could still be improved, such as calling temp.toks[0].substring(1) only once and using a variable the multiple times it is needed. In all actuality, the substring isn't necessary.
Another note is I don't think example 2 is working like it is supposed to be, but that is merely speculation. If the serverside commands do not start with "/", they are not being evaluated in that example, and if they do begin with "/", then the "/" is being passed along to the server. Doesn't make much of a difference in script performance, but I must remind that removing the "/" from the command on the serverside as well is silly. If example 1 could be tweaked to filter out non-commands from ChatBar, I would go with that one. |
well, which one takes the least CPU usage?
yeah im a noob whatever |
Not that bad of a question though, I've made scripts that increased actual cu usage.
|
Quote:
|
For more options, I would go for #1, for less #2
|
Quote:
What I was getting at is that say ChatBar calls onAction. The second one is weeding out right off the bat all parameters from ChatBar that could never be the case. Option one loops through each of the cases for everything passed from ChatBar, regardless of if it might be a case. That is not particularly desired; it runs up CPU usage. |
Thus the major thing I've been wondering about. I was thinking cases would be similar to checking an array for a match since it's only comparing the case "blah": line. I think it would be very close in terms of efficiency. You could argue that once a match is found serverside, it has to go through all cases below it but does it actually process cases since it has found it's match already?
Also, my method doesn't send incorrect commands serverside >_<. Kuji would need another .index() for this thus less efficiency clientside ^^ . |
Quote:
An array would do the trick. |
Maybe this?
PHP Code:
|
Cases are a lot cleaner and easier to modify, especially when you want multiple cases doing the same thing, without the need of calling the same function multiple times.
|
Quote:
PHP Code:
|
Combination of the two XD
|
| All times are GMT +2. The time now is 07:37 PM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.