timm@runxtsa.runx.oz.au (Tim Menzies) (04/11/90)
I was doing some benchmarks on some Smalltalk/V code the other day i came up with some puzzling times. I ran the same program 10 times and recorded the time take for each run. I repeated this process five times. The times varied from 5500 milliseconds to 1650 milliseconds, as follows: -------------------------------------------------- run number 1 2 3 4 5 6 7 8 9 10 -------------------------------------------------- repeat 1 | 1760 1980 3850 1870 2310 2750 1760 3245 1815 2200 repeat 2 | 1760 2310 5500 1925 1870 3190 1870 2750 2145 1870 repeat 3 | 1815 2365 4015 1980 1870 3300 1760 3025 2035 1760 repeat 4 | 2035 1815 4950 1815 3080 1980 1760 3300 1815 3080 repeat 5 | 1650 1760 4675 1760 1870 3190 1870 3190 1870 1760 This was on a PS-2 model 80 (no maths co-processor) where I believe the smallest clock tick is 55 milliseconds (i.e. the variations in the run time can not be accounted for by quirks in the way I read the clock). Now I understand that Smalltalk runs on its own virtual machine; a mini-operating system if you like. Such a virtual machine must occaionally steal time from the program to take care of its own house-keeping. Even so, the variations describe above are a little extreme (to say the least). My code is given below. As near as I can tell, I'm not creating lots of new objects, except smallIntegers (which I would expect to appear and disappear cleanly). Is there something wrong with Smalltalk/V? To date I have found it to be an excellent product. Does this sort of behavior repeat under Smalltalk 80? Or can anyone offer me a sensible explaination of these numbers? Thanx in advance tim menzies -------------------------------------------------------------------- OrderedCollection variableSubclass: #StopWatch instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' ! !StopWatch class methods ! demo |x wait ticks| ticks := 10. wait := 20000. x := StopWatch new. ticks timesRepeat: [ 1 to: wait do: [:i| true]. x tick]. ^x ms! "writes a line in the above table" new ^super new initialize! ! !StopWatch methods ! initialize self tick! ms |last delta| last := self first. ^(self copyFrom: 2 to: endPosition) asArray collect: [:time| delta := time - last. last := time. (delta // 55) * 55]! "55 is the smallest clock tick on my machine" tick self add: Time millisecondClockValue.! !