[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Simple calculator

This thread sort of begs the question, "how many Debian developers does
it take..."

Anyhow, I have been very impressed with some of the calculators proposed 
here; so impressed that I coded them all up as bourne shell functions
and did some profiling.  Because, after all, the speed of your two-digit 
division is important stuff!

This test was only slightly more scientific than the back of a shampoo
bottle, but here are some average results on my PPro 200 for 20 over 13:

bc (Joey Hess): 1.53846153846153846153
gs (Rob Browning): 1.53846157
guile (Rob Browning): 1.53846153846154
metafont (Marcus Mrinkmann): 1.53847
perl (John Lapeyre): 1.53846153846154

Perl and bc seem comparable in speed, but bc wins because it's using bcd
and has more precision.  Surprisingly, metafont is in third place, but I
think the metafont and gs solution score big points for being cool
hacks.  gs loses some points for rounding a 3 up to a 7(!), though.
Guile, well, guile's a new language :-)

The winner: metafont, for coming in with respectable speed *and* being a 
   really cool hack.  Congratulations to Marcus.

Here's the benchmark script, you can put these functions in your
.profile if you're a sadist:

# (Because it doesn't work with ash :-)

bc_calc () {
  # Joey Hess <joey@kitenet.net>
  echo $* | bc -l
echo -n "bc: "; time bc_calc 20/13

gs_calc() {
  # Rob Browning <rlb@cs.utexas.edu>
  # With some cleanup by myself
  echo $* | gs -q -sDEVICE=nullpage | sed 's/^GS>//'
echo -n "gs: "; time gs_calc 20 13 div ==

guile_calc() {
  # Rob Browning <rlb@cs.utexas.edu>
  guile -c "(display ($*))"; echo
echo -n "guile: "; time guile_calc / 20 13

mf_calc() {
  # Marcus Mrinkmann <Marcus.Brinkmann@ruhr-uni-bochum.de>
  # With some cleanup by me
  # Extra geek points for this one.
  cat <<EOD | mf | sed -n 's/\*>> \(.*\)/\1/p'
a=$*; show a;
echo -n "metafont: "; time mf_calc 20/13

perl_calc() {
  # John Lapeyre <lapeyre@physics.Arizona.EDU>
  perl -e "print $*,\"\n\""
echo -n "perl: "; time perl_calc 20/13

Neale Pickett, propellerhead       Contact information in headers
Los Alamos National Laboratory, Network Engineering Group (CIC-5)

To UNSUBSCRIBE, email to debian-devel-request@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org

Reply to: