Bug 48259

Summary: Improve StatCalculator performance by using HashMap
Product: JMeter - Now in Github Reporter: ahit <andrey.hitrin>
Component: MainAssignee: JMeter issues mailing list <issues>
Status: RESOLVED FIXED    
Severity: enhancement    
Priority: P2    
Version: Nightly (Please specify date)   
Target Milestone: ---   
Hardware: PC   
OS: All   
Attachments: Use HashMap for keeping values distribution instead of ArrayList

Description ahit 2009-11-21 21:58:14 UTC
Created attachment 24582 [details]
Use HashMap for keeping values distribution instead of ArrayList

There is no actually need to store *each* value separately in StatCalculator class. It's enough to save only counter of occurrences for every value. I propose HashMap class for that instead of ArrayList.

HashMap provides several major benefits:
 - It occupies less memory than ArrayList, especially for large data sets, because every inserted value will be kept within just one pair (key-value).
 - It has faster data insert (there is no need to call Collections.binarySearch() for every addValue(), insert into HashMap has O(1) complexity)
 - It still stays quite fast for reading. It calls for sorting in modified getPercentPoint() method, but sorts only keys. A number of unique keys is usually much less than total count of inserted values.

Sorry, I didn't check modified StatCalculator on real data yet, just run JMeter tests. I will do it after the weekend. But I think it will work fine.

I worked at SVN build 883037.
Comment 1 Sebb 2009-12-14 16:59:20 UTC
Thanks for the patch.

This has been applied to SVN:

URL: http://svn.apache.org/viewvc?rev=890589&view=rev
Log:
Bug 48259 - Improve StatCalculator performance by using HashMap

I made a few changes:
- instead of sorting the keys and using last or first to get max and min the code keeps track of the values.
- the sorted TreeSet is cached
- use MutableLong (Commons LANG) instead of Long
Comment 2 The ASF infrastructure team 2022-09-24 20:37:44 UTC
This issue has been migrated to GitHub: https://github.com/apache/jmeter/issues/2314