|
I started this journey to find the best all-around method for shifting bank containers (when you take an item out completely and all of the items after it shift) and which one would be best for my use case, which is a low-capacity bank that you can slowly expand through in-game means. This means that I found a bunch of server sources, yoinked the code and sort of retrofitted it to work with the code I have so I can test it. I've traced a lot of these sources back to ABOUT where they were created and I've named them as such. And converted them to kotlin and optimized where I can.
Before we go any further, I am using my own container implementations which are frankly probably not the greatest performance, but performance of those shouldn't have a significant impact on these tests (or on anything honestly). I use conventions to avoid nulls that some find odd. For example, I useInvalidItem
(an impl where an item meets the conditions to be invalid, id is equal to or less than 0) in place of null. I will be using "empty" as a term for an empty slot, which in most cases isnull
, or in my caseInvalidItem
The Methods
Here's a breakdown of the methods and their statistics.
The statistics I use will be some pretty important statistics that are helpful to determine usefulness of most things in most cases, and here's the ones I'll be using. I opted out for most because median and minimum will be close enough and median is pretty much your value you can bet on having in nearly all cases.
minimum
- The minimum time it took a call to complete. Important because this shows your best case scenario and a goal to work towards converging onmedian
- The median time it took a call to complete. Much more accurate measurement towards the majority than average.
Here's the list of the methods used
- nbxShift was written by me for my project NBX. Like most things I do, I don't have performance in mind initially. I am interested in writing informative code to teach people and let them explore how to do the same thing but in a different way
- nbxPartitionShift was also written for my project. This one was more of an experiment to see how simple I could do it using the standard library. Turned out nice and cute and worked exactly how I wanted to.
- dementhiumShift I found this in pretty much every source that used dementhium as it's base. The ones it wasn't in were the ones I rewrote. This is a really interesting one because of it's lack of interestingness.
- codeUsaShift This almost exact code was found in a LOT of 474 to 562s. It's also relatively simple and it's beautiful.
- rsmodShift This code works well and is written well. It looks like it actually combines some older methods, whether on purpose or purely by coincidence.
Testing method
Randomly generated bank container
- All items stack
- Only shift when a slot is empty
- All of the slots before an empty slot are occupied
Profiled using IntelliJ Profiler v2.8.3
Only the shift is measured
Each test uses a different sized container (100, 500 and 1000) but will each run 5000 times
Method 1: NbxManual
Spoiler for data:
Summary: Dependency free, crafted with readability in mind, scales O(size), the already-low base numbers can be optimized for specific item classes but uses generic item class
Method 2: NbxPartitionJoin
Spoiler for data:
Summary: Simple to write, scales relatively well, the high (~600% of manual) base numbers can be optimized writing specific collection functions for specific item classes
Method 3: CodeUSA
Spoiler for data:
Summary: Simple once you understand, scales relatively well, the mid-range base numbers can be optimized by taking some shortcuts that weren't there in the original code
Method 4: Dementhium
Spoiler for data:
Summary: Simple, quick, scales very well, seems hard to optimize in performance sense but it could be more readable (in my opinion)
Method 5: RsMod
Spoiler for data:
Summary: High base numbers, a seemingly bad performing combination of CodeUSA and Dementhium, can be optimized
The second coming
I wanted the best of all worlds and more. I took the time to understand the code and their performance and ended up creating my own monster using none of that information, really.
Spoiler for data:
summary: i optimized dementhium away
Not done making container, but it will come with something even better
« Previous Thread | Next Thread » |
Thread Information |
Users Browsing this ThreadThere are currently 1 users browsing this thread. (0 members and 1 guests) |