Repository navigation
Add benchmark to compare notifying listeners stored in lists and arrays - #6
Merged
Merged
Conversation
Measures the time and memory to notify listeners stored in the immutable lists created by the Listeners class (cloudsimplus/cloudsimplus#586) and in plain arrays. Run with -prof gc to see if the for-each loop creates an iterator. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
manoelcampos
added a commit
that referenced
this pull request
Oct 20, 2026
…ys (PR #6 and #9) Measures the time and memory to notify listeners stored in immutable lists (as created by the Listeners class from cloudsimplus/cloudsimplus#586) and in plain arrays. Run with -prof gc to see if the for-each loop creates an iterator. The benchmark builds the lists itself with List.of(array), which gives the same List classes CloudSim Plus uses, without depending on the Listeners class. This way, it compiles against both CloudSim Plus 8.5.1 and 9. Closes #8 Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related to cloudsimplus/cloudsimplus#586 (PR cloudsimplus/cloudsimplus#593)
Summary
Adds
ListenersNotificationBenchmark(neworg.cloudsimplus.listenerspackage) to check if storing listeners in plain arrays, instead of the immutable lists created by theListenersclass, makes notification faster.A for-each loop over a
Listcallsiterator(), which creates an object, unless the JIT removes it with escape analysis. A for-each loop over an array creates no object. The benchmark should be run with-prof gcto see if the iterator is created (gc.alloc.rate.norm).EventInfo, so only the iteration is measured.single*: notifies one list (or array) with 0 to 3 listeners. Each param value runs in its own fork, so the loop only sees oneListclass.mixed*: notifies lists with 0 to 3 listeners in each operation, like a simulation with many VMs that have different numbers of listeners. This way, the loop sees bothList12andListN, as in a real simulation.Results
java -jar target/cloudsimplus-benchmarks-9.0.0-SNAPSHOT-uber.jar ListenersNotificationBenchmark -f 1 -wi 3 -w 1s -i 5 -r 1s -prof gc(JDK 25)When the loop sees only one list class, escape analysis removes the iterator, and lists and arrays perform the same.
When it sees both classes (the realistic case), an iterator is created for each list (32 B × 4 lists = 128 B/op), and the list version is ~67% slower.
🤖 Generated with Claude Code