Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Clean up strategy test
(version: 1)
Comparing performance of:
Clean by half vs Clean one by one
Created:
one year ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<!--your preparation HTML code goes here-->
Script Preparation code:
var i = 0, MAX_SIZE = 10, a; var loop = 100 var map = new Map(); for (i = 0; i < MAX_SIZE; i++) { map.set(i, i); }
Tests:
Clean by half
/*When writing async/deferred tests, use `deferred.resolve()` to mark test as done*/ for (i = MAX_SIZE; i < loop; i++) { map.set(i, i); if (map.size >= MAX_SIZE) { let count = MAX_SIZE / 2; for (const key of map.keys()) { map.delete(key); count--; if (count <= 0) { break; } } } }
Clean one by one
/*When writing async/deferred tests, use `deferred.resolve()` to mark test as done*/ for (i = MAX_SIZE; i < loop; i++) { map.set(i, i); if (map.size >= MAX_SIZE) { const firstKeyIt = map.keys().next() if(!firstKeyIt.done) { map.delete(firstKeyIt.value) } } }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Clean by half
Clean one by one
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36
Browser/OS:
Chrome 133 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Clean by half
185287.8 Ops/sec
Clean one by one
129700.4 Ops/sec
Autogenerated LLM Summary
(model
gpt-4o-mini
, generated one year ago):
The benchmark you provided focuses on comparing two different strategies for cleaning up entries in a JavaScript `Map` data structure. The benchmark tests are designed to analyze the performance of two specific deletion methods for entries in the `Map` and measure how many operations can be executed per second. ### Benchmark Overview - **Test Strategies**: 1. **Clean by half**: This strategy attempts to delete half of the entries in the map each time the number of entries meets or exceeds a maximum size. 2. **Clean one by one**: This strategy deletes only one entry from the map when the maximum size is reached, specifically the first entry according to the insertion order. ### Pros and Cons of Each Approach #### Clean by half - **Pros**: - More efficient in terms of the number of deletions performed in each iteration since it removes multiple entries at once. This can lead to better performance, especially when a large number of entries needs to be removed. - Makes use of the map's inherent properties, potentially reducing the number of iterations needed in the loop. - **Cons**: - May lead to more complex code, particularly in cases where the conditions surrounding deletion need to be managed carefully (e.g., keeping track of the count). - If the map contains many entries and only a few need to be deleted, this method may be overkill and not optimal in terms of time/space complexity. #### Clean one by one - **Pros**: - Simpler implementation, easy to understand and follow. It focuses on a single entry removal, which can be clearer from a logic standpoint. - Reduces the likelihood of dealing with edge cases involving multiple deletions and complex condition checks. - **Cons**: - Less efficient, especially when a lot of entries need to be deleted. This method may lead to a higher execution time since it might involve multiple separate deletion operations instead of a single large batch operation. - Can result in slower performance as the size of the `Map` grows and if many entries above the maximum size threshold are present. ### Alternatives - **Bulk Deletion**: Some libraries might have functions that allow bulk deletion based on certain criteria, offering a middle ground between complex manual deletion strategies and one-by-one deletes. - **Using Arrays**: If order does not matter as much, alternatives like arrays or objects could be utilized with different cleaning algorithms, like filter-based approaches. This may provide different performance characteristics. - **Different Data Structures**: Depending on the use case, exploring other data structures like Sets or even custom implementations may yield better performance for specific types of data management. ### Libraries and Tools The benchmark in this context uses native JavaScript features (i.e., `Map`, `for` loops) without relying on any additional libraries. The purpose of the `Map` data structure is to provide an efficient way to store key-value pairs where both keys and values can be of any type, for quick retrieval and manipulation. Overall, this benchmark illustrates the trade-offs between batch and individual processing strategies using JavaScript's `Map`, enabling software engineers to choose the approach that best fits their performance and complexity needs based on the specific context.
Related benchmarks:
Test map size
map length
Map get VS Map has get3
Map get VS Map has get part 2
Map get VS Map has get part 3
JS Map get VS JS Map has
Map has vs set
Clean up strategy
Clean up strategy test 2
Comments
Confirm delete:
Do you really want to delete benchmark?