VASmalltalk: Delay forMilliseconds:

I use Delay>forMilliseconds: quite often is all various multitasking experiences and background processes and during producing some podcasts for VASmalltalk about calling external threads I noticed, that the called Pascal library did a much better job for delaying the current process than my VASmalltalk.

When running code like this:

summe := 0.
1 to: 100 do: [ :each |
	| first second |
	first := Time millisecondClockValue.
	(Delay forMilliseconds: 100) wait.
	second := Time millisecondClockValue.
	summe := summe + (second - first).
].
Transcript cr ; show: 'Average ms for waiting', (summe / 100) asFloat printString

one may notice, that VisualWorks works pretty fine for waiting values >= 15 ms. For values like 30,50,70,90, …. it actually needs (on the average) 10ms more, leading to: 40, 60, 80, 100, ….
When running with ms values like 40, 60, 80, 100 it stay pretty well at that value ….

VASmalltalk is pretty conservative here. Values below 100ms will actually not work well. For value 0 <= x <= 100 it will need 100ms waiting time – and even with greater value be prepared to wait 100ms longer. To get a more accurate behaviour of this method you may change the value of the class variable InterruptPeriod from e.g. 100 (original value – therefore the 100ms above) to 10 and change

Delay>forMilliseconds: millisecondCount
  millisecondCount < 0 ifTrue: [ ExCLDTValueOutOfRange signalWith: 1].
  ^super new
       delayTime: ((millisecondCount - InterruptPeriod) max: 0);
       yourself
This entry was posted in Smalltalk. Bookmark the permalink.