From: Isaac Gouy Date: 2006-08-02T05:00:07+09:00 Subject: Re: For performance, write it in C - Part 3, Source code now available Thomas E Enebo wrote: > On Wed, 02 Aug 2006, Charles O Nutter defenestrated me: > > > > First, some notes on benchmarking: > > > > - NEVER include IO when benchmarking a numeric algorithm; IO speeds vary > > greatly from system to system and can vary from run to run depending on what > > else is happening > > IO can be noisy. I say avoid it for any benchmarking since it can > greatly influence timings. Usually the IO is not what you want to > measure so why add this variable into things? > > > - If you're building up a large chunk of strings, write to an internal > > buffer and then write out at the end; don't write for every little tiny > > operation. At the very least, use a buffer per-line, rather than a separate > > write for every element on that line. > > I just informally thought I would measure a few things involving IO. > I only changed the printing and nothing else: > > Unaltered test: ~3.8s > Use of StringBuffer to print out a single row: ~2.1s > Use of StringBuffer for entire run: ~1.5s > Preallocated StringBuffer for entire run: ~1.4s > > As you can see IO can have a large affect on clock time. I demonstrated > that in Java's case the IO in the benchmark accounted for over 2/3 of the > wall clock time (which is interesting because a decent chunk that is > left over is JVM startup overhead). > > Some stack allocated space will likely improve the C run as well (and in > this case you can output it in a single write system call). > > -Tom > > -- > + http://www.tc.umn.edu/~enebo +---- mailto:enebo@acm.org ----+ > | Thomas E Enebo, Protagonist | "Luck favors the prepared | > | | mind." -Louis Pasteur | As you're having so much fun, let me suggest you try converting the OutputStrings to byte-arrays, and pre-allocating a byte buffer for output like the approach taken with this program http://shootout.alioth.debian.org/gp4/benchmark.php?test=fasta&lang=java&id=2