[q]squeak is too slow?

=?ks_c_5601-1987?B?wMzD4byu?= stonecold at jupiter.kaist.ac.kr
Wed Dec 8 10:46:46 UTC 2004


I attach the file which represent Voronoi Game class.
The part which cuase problem is in 'nextLocal'.
In 'nextLocal', 900 loop occur.
For each loop, another 900 loop occur for computing minimum(using 'score'
message). 
It is difficult to explain what Voronoi game is here. So I omit this.
But as you see code, you can notice what problem is.

Thanks again for many help.

-----Original Message-----
From: squeak-dev-bounces at lists.squeakfoundation.org [mailto:squeak-dev-
bounces at lists.squeakfoundation.org] On Behalf Of Yoshiki Ohshima
Sent: Wednesday, December 08, 2004 1:57 PM
To: The general-purpose Squeak developers list
Subject: Re: [q]squeak is too slow?

  Hello,

> 'Something' is just array manipulations.
> Asuume that (j,k) are a matrix(30 by 30).
> For each (j,k) I want to compute sum of distance from (j,k) to all others.
> Finally we have to get a minimum among sums.

  You still didn't tell us how your code exactly looks like (why?), but
is it something you can do with the following?

	| a b sum xDiff yDiff sq r |
	a _ (1 to: 30) inject: (FloatArray new: 0) into: [:s :t | s, ((1
to: 30) as: FloatArray)].
	b _ (1 to: 30) inject: (FloatArray new: 0) into: [:s :t | s,
(FloatArray new: 30 withAll: t)].
	r _ FloatArray new: 900.
	1 to: 30 do: [:j |
		1 to: 30 do: [:k |
			sum _ 0.0.
			xDiff _ a - j asFloat.
			yDiff _ b - k asFloat.
			sq _ (xDiff * xDiff) + (yDiff * yDiff).
			sq _ sq collect: [:x | x sqrt].
			sum _ sq sum.
			r at: ((j - 1) * 30) + k put: sum.
		].
	].
	^ r min.

(Set up 'a and 'b' if you need to put some values, but shouldn't
affect the performance.)

This runs in about 1.5 sec on my computer.  Interestingly, more than
95 percent of time goes to

			sq _ sq collect: [:x | x sqrt].

line, so if you comment this line out, it runs in about 60ms.  If you
change the algorithm to avoid the square root calculation, it should
run in around 60ms.  (If you have a modestly fast computer.)

  Note that the above code allocates a lot of redundant arrays.  One
can imagine to omit these allocation.

  By the way, ... what kind of computer you're using, and how the code
you tried exactly look like?  If you don't tell us that, we can't
discuss any more interesting stuff.  A very, very naive version I
tried runs in about 4 sec, so still something might be written poorly
in your code, or the computer is slow from today's standard, or
something like that.

-- Yoshiki

P.S.
  I like to abuse the FloatArray and friends...
-------------- next part --------------
A non-text attachment was scrubbed...
Name: VoronoiGame.st
Type: application/octet-stream
Size: 5673 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20041208/3e27342e/VoronoiGame.obj


More information about the Squeak-dev mailing list