Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!weretis.net!feeder4.news.weretis.net!news.musoftware.de!wum.musoftware.de!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: 3 Jul 2011 01:34:30 GMT Organization: None Lines: 68 Message-ID: <979v96F7epU1@mid.individual.net> References: <976q3jF3etU2@mid.individual.net> <9796kgFoijU3@mid.individual.net> X-Trace: individual.net HnpFkFn4ofc4qEYhW1cf+gjvpTnwPFgH6ibSnKz5QMy7lYul8c X-Orig-Path: not-for-mail Cancel-Lock: sha1:cD4eNRADLzdZxFM0Hm1S3z22gOM= X-Newsreader: trn 4.0-test76 (Apr 2, 2001) Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:5827 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 ] > > Oh, I asked about that. One apparently can not pass a function > > pointer parameter as in C. The ways that were posted involved lookup > > every time AFIACS and I judged that it might swamp what I was > > measuring (checking if a character were in a set). So, to my chagrin, > > I had to go with cut-and-paste. > > Without experimenting to find out, of course .... > > It seems to me that virtual method invocations are so common in > Java that they would be well-optimized. But if you want to claim > that the code you eventually hope to produce won't have one, well, > yeah, that's true, so maybe it matters. Then again, wouldn't a > similar argument apply to C with function pointers? Maybe not. > I don't seem to be able to think this through as carefully as > I'd like. > > Anyway, I was curious, so I ran your code and my revision [1], and > the results were -- surprising [2]. I noticed, by the way, that > all three of your parse methods make a call to SequentialSearch, > assigning the result to a variable that apparently isn't used. > Thinking that *might* be a mistake, I also tried your code and my > revision with that possibly-extra call removed. 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 .... > [1] Message-ID: <96k6atFt60U2@mid.individual.net> > > [2] I tried this on several different systems, all Fedora Linux > running Java 1.6.0_21 but different hardware and different releases > of Fedora. [ snip ] > Your code was fairly (but not 100%!) consistent in showing > treeset-based search to be fastest, followed by binary search and > then sequential search, though sometimes the difference between > sequential and binary was small. My code was -- well, this is where > it's surprising. On most of the systems where I tried it, treeset > search was fastest, but sequential search was faster than binary > search; on one system, however, the order was as for your code. > Your code was pretty consistently faster than mine, though usually > not by a lot (less than 1%). 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 .... [ snip ] -- B. L. Massingill ObDisclaimer: I don't speak for my employers; they return the favor.