Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!newsfeed.kamp.net!newsfeed.kamp.net!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: 11 Jul 2011 22:37:59 GMT Organization: None Lines: 65 Message-ID: <981ca7FlgtU4@mid.individual.net> References: <97ublnFag8U4@mid.individual.net> X-Trace: individual.net IVKU+035GwWT0niudzoxRw0QqX7AlTaPDGVNsc4k8uUZCrwdSX X-Orig-Path: not-for-mail Cancel-Lock: sha1:cn5qf5tTiWYat4LtzVNPOMeLkfA= X-Newsreader: trn 4.0-test76 (Apr 2, 2001) Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:6089 In article , Gene Wirchenko wrote: > On 10 Jul 2011 19:08:40 GMT, blmblm@myrealbox.com > wrote: > > >In article , > >Gene Wirchenko wrote: > > [snip] > > >> Micro-optimisation is a nasty sin. > > > >Yeah, yeah .... I guess it just seems strange to me that you went to > >all the trouble of writing code to benchmark various approaches -- > >suggesting that sometimes you *do* engage in micro-optimization -- > >but are resistant to trying one more approach that (in my tests > >anyway) sometimes reduced execution time by almost 50%. Just sayin', > >"whatever", .... :-)? > > It should be obvious to you why someone might do that. > > The part that I was benchmarking is critical to my program. It > is repeatedly used since it is called for every non-newline character > in a file. Initialising a set of characters does not happen nearly so > often. I know I don't always express myself with 100% clarity, but really, I must be doing worse than usual here .... I did not attempt to measure speed of initialization. That would indeed be silly, and I don't understand why you would think .... Well, be that as it may: What I did was add to your benchmark code a test for LinkedHashSet, identical to the one for TreeSet except for the type of set. When I ran the resulting code, the output indicated that LinkedHashSet was sufficiently faster than TreeSet for me to think you might be interested. "Faster" here means "faster by your criterion as I understand it". If you've made a decision and want to stop dithering about whether you might have missed something someone thinks might suit you better, okay, but .... Well, whatever. By the way, I'm still mildly curious about why you decided, without testing, that it would not be a good idea to follow the suggestions you were given about avoiding all that tedious cut-and-paste. In Message-ID: you wrote > 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. It's interesting to me that you were able to reach this conclusion (that using Java's alternative to function pointers *does* affect benchmarking results) without doing any experiments -- I think you're probably right, but I did some experiments before coming to the same conclusion. "Whatever" again. -- B. L. Massingill ObDisclaimer: I don't speak for my employers; they return the favor.