• Hey! Register here to create your account, engage with the community, and talk about what is new!

RemoveListIndex(1) is 10x faster than TrimList(2)

stinkey

Forum adept
Joined
Sep 8, 2020
Messages
225
Reaction score
74
Yep, it's true.

Now, you may be wondering: so what? Well, as we all know, we remove the first indices of lists all the time. Several thousands of times per second. There is no need to try to disprove this claim. Everyone knows this to be true.

So, I did some tests with the following code:

C-like:
function main() {
    list = RepeatText("m", 1000);
    list = SplitText(list, "");
    i = 0;
    repeat Forever() {
        i ++;
        copy = list;
        repeat Multiple(100) {
            // either
            copy.trimList(2);
            // or
            copy.removeListIndex(1);
        }
    }
}

In this code example, I am repeatedly performing the action until Lagslayer begins to cry and wail and scream and shout at me for having an infinite loop.

Now, the results

TrimList: 476, 596, 558; on average ~543.3
RemoveListIndex: 7291, 7621, 6488; on average ~7133.3

So, we can see that RemoveListIndex manages to squeeze in a whopping 13x as many iterations as TrimList. However, I believe that RemoveListIndex may be upwards of 20x faster, given that we are also copying the list into a new variable every something something iterations.

Now, when you are removing the "command" from your custom command "@command" to parse the arguments ["command", "foo", "bar"], you will know which one to use! I know this will help many people create a more efficient and performant game. Ahem...

Thank you for your time.
 
Last edited:

shiverdog

Well-known member
Joined
Sep 8, 2020
Messages
75
Reaction score
41
Thank you, I had an issue with my players spamming @item thousands of times per second, my plot didn't like that very much.
You're a lifesaver!
 
Top Bottom