gcd:, optimization

Daniel Vainsencher danielv at netvision.net.il
Sat Feb 14 21:13:05 UTC 1998


I've been playing around with the gcd: algorithm. Implementing a very
clean and simple version of Euclid's algorithm, I did manage to get
significantly better results than the current implementation,
probably due to using a constant number of non-primitives.

That was on a very simple benchmark I devised on the spot.

Originally, I wanted to implement Euclid's for use in a C++ exercise
that involves Fractions. So naturally, I wanted to see if I'd
improved Squeak Fraction calculations any. My new (simple, ad hoc)
Fraction benchmarks show meagre if any rewards for my efforts.

All this amounts in my facing two questions that I think are worth
asking (yes, finally, the point) - 

A. How do you find out the real relative costs of parts of an
algorithm, in Squeak?
It seems to me now that the big deal in Fraction arithmetic is the
allocation, but I certainly wouldnt bet on it.

B. Having decided you want to improve the performance of a specific
feature, how do you go about devising good benchmarks, to find out
whether you've succceded?
Especially, to find out what parts of the system use that algorithm,
and how?

BTW, the code I settled upon is - 

gcd: other
 | m n t |
m:= (self abs) max: (other abs). "This duplicates the abs sends and
tests in min:, max:, but I don't think that matters much"
n:= (self abs) min: (other abs).

[n = 0] whileFalse: [
	t := m \\ n.
	m := n.
	n := t.
].

^m.

Any suggestions, comments?
-----------
Daniel Vainsencher 
A member of the First Millennial Foundation,
making space a place to live in. Visit our CyberHabitat at
http://www.millennial.org





More information about the Squeak-dev mailing list