Newsgroups: comp.lang.smalltalk
Path: cantaloupe.srv.cs.cmu.edu!rochester!udel!delmarva.com!newsfeed.internetmci.com!howland.reston.ans.net!xlink.net!ins.net!heeg.de!gustav!hmm
From: hmm@gustav (Hans-Martin Mosner)
Subject: Re: VW2 #do:,#at: - array bounds checking? Opinions requested.
Message-ID: <DEE0Ip.2FJ@heeg.de>
Sender: uucp@heeg.de
Organization: Georg Heeg Objektorientierte Systeme, Dortmund, FRG
X-Newsreader: TIN [version 1.2 PL2]
References: <DE1yrs.6s8@Cadence.COM> <26lvFr$03A@zoe.pcix.com> <42ai8m$4ai@ixnews6.ix.netcom.com>
Date: Mon, 4 Sep 1995 15:32:48 GMT
Lines: 44

After reading a lot of opinions, I decided to post some facts.
I did a mini-benchmark for measuring just how long a single
at: message send takes. The benchmark follows:

| a million t1 t2 thousand |
a := Array with: 1.
million := 1000000.
thousand := million/1000.0.
t1 := Time millisecondsToRun: [million timesRepeat: [a at: 1]].
t2 := Time millisecondsToRun: [million timesRepeat: [a at: 1. a at: 1]].
Array	with: t1 / thousand
	with: t2 / thousand
	with: t2-t1 / thousand

Select it, and perform a 'print it'.
What you get is an Array of 3 numbers:
1. The number of microseconds (millionth of a second) to execute
   one turn of the first loop,
2. The number of microseconds for one turn of the second loop,
3. The difference, that is the number of microseconds for one at:.

I executed this code several times on my good old Sun IPX just to
see that the results are stable, and got the following numbers
(rounded to 0.05 microseconds)

1.85 usecs per iteration of the first loop
3.10 usecs per iteration of the second loop
1.25 usecs per at: access
0.60 usecs per empty loop iteration (calculated from the other numbers)

This means that you can do about 800000 (eight hundred thousand)
at: accesses per second. If this dominates your total time, then
the rest of your algorithm is probably so simple that re-coding
the whole stuff as a C routine to be called via DLLCC or primitive
is easy to do. Having a primitive just to omit the bounds checking
will most certainly not help!

Hans-Martin

--
+--- Hans-Martin Mosner -------- Senior Smalltalk Guru ---+
| These opinions are entirely ficticious.  Any similarity |
| to real opinions is purely coincidental and unintended. |
+--- <hmm@heeg.de> ------ URL:http://www.heeg.de/~hmm/ ---+
