Note that I haven't profiled memory usage in the different scenarios. I also ran TestForNull with final variables, but the difference was negligible. However, if threading is an issue, AtomicLong might be more attractive than the others (I'm not really sure). It would appear that only the MutableInt method and the Trove method are significantly faster, in that only they give a performance boost of more than 10%. MutableInt: 25.747 seconds (1.19 times as fast).Trove: 26.313 seconds (1.16 times as fast).TestForNull: 28.804 seconds (1.06 times as fast).AtomicLong: 29.780 seconds (1.03 times as fast).The ContainsKey method was, as expected, the slowest, so I'll give the speed of each method in comparison to the speed of that method. I'll present the results first and the code below for those who are interested. averaged the four results for each method. performed all five tests in series, and then did this another three times.timed the loop of 10 iterations but not the I/O operation and recorded the total time taken (in clock seconds) essentially using Ian Darwin's method in the Java Cookbook.Since this took an average of only 3 seconds, I had it perform the frequency count (not the I/O) 10 times. Each class had to perform an operation typical of the scenario I presented: opening a 10MB file and reading it in, then performing a frequency count of all the word tokens in the file. created five classes that were identical except for the differences shown below.the "Trove" method suggested by jrudolph.the "AtomicLong" method suggested by Hank Gay.the "TestForNull" method suggested by Aleksandar Dimitrov.the "ContainsKey" method that I presented in the question.I've gotten a lot of good answers to this question-thanks folks-so I decided to run some tests and figure out which method is actually fastest.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |