Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: blmblm@myrealbox.com Newsgroups: comp.lang.java.programmer Subject: Re: StringBuilder Difficulties Date: 5 Jul 2011 19:12:39 GMT Organization: None Lines: 62 Message-ID: <97h616FhaeU3@mid.individual.net> References: <9796kgFoijU3@mid.individual.net> <979v96F7epU1@mid.individual.net> X-Trace: individual.net omG90Au+QDN1axMBzwglzgWR7wwTYflwMxQpdApTjCxvtWiypf X-Orig-Path: not-for-mail Cancel-Lock: sha1:5CSzu8xpjtfcNUojfQdmQ2p9C28= X-Newsreader: trn 4.0-test76 (Apr 2, 2001) Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:5863 In article , Gene Wirchenko wrote: > On 3 Jul 2011 01:34:30 GMT, blmblm@myrealbox.com > wrote: > > >In article <9796kgFoijU3@mid.individual.net>, > >blmblm@myrealbox.com wrote: > >> In article , > >> Gene Wirchenko wrote: > >> > On 1 Jul 2011 20:47:47 GMT, blmblm@myrealbox.com > >> > wrote: > >> > > >> > >In article <6cqp07tiug2nu8u6ififvvek1694fkpfi1@4ax.com>, > >> > >Gene Wirchenko wrote: > >> > >> On 30 Jun 2011 20:30:00 GMT, blmblm@myrealbox.com > >> > >> wrote: > > > >[ snip ] > > >UPDATE: I just re-read the previous threads and realized that > >your code actually calls SequentialSearch in the method that's > >supposed to be timing BinarySearch. Once I fix that .... > > Yeah, I caught that goof later, too. Or was that one pointed > out? There was at least one goof that got pointed out to me. Cut and > paste is a horrible way to have to do it. I think there was one mistake that was pointed out (wrong search) and one that was not (extra use of SequentialSearch in all methods). > [snip] > > >Both programs (yours and mine) now consistently report sequential > >search to be faster than binary search. Weird, but not as weird as > >the two being different in that regard .... > > That is not the result that I got. Sequential search was > occasionally faster but usually a bit slower the binary search. Interesting. So maybe I should try this on a few more systems .... When I do, I find that on newer systems indeed binary search was at least a bit faster. On older ones, not so much. Patricia Shanahan's theory (about why binary search could be slower) makes sense to me and also provides a plausible explanation of why results could vary among systems. > Someone posted links about the difficulty of Java benchmarking. > If it really mattered (checking for *small* differences), I would use > them and may well in a future test when it does. The difference > between the binary search and the Treeset search was sufficiently and > consistently different that I went with Treeset. What I found is that HashSet was noticeably faster on all the systems where I ran the benchmarks. Unless you need for the set to be sorted (and it's not apparent from your code that you do), why not .... ? (I'm curious too about why you chose TreeSet in the first place. ? ) -- B. L. Massingill ObDisclaimer: I don't speak for my employers; they return the favor.