DELAY PROCESS(ProcNum;1) seems to delay 2 to 4 ticks [JPR]?

Tony Ringsmuth (4/7/14 11:07AM)


Tony Ringsmuth (4/7/14 11:07 AM)

(I"m hoping that JPR can shed light on this situation)

MY QUESTION:
Is there any way to get a loop to run a few hundred times/second,
while NOT
becoming a processor hog?

THE FULL STORY:
I have a tcp listening process that I'm trying to optimize:  Ideally,
I'd
like to cycle some very light code about 300x/second.  I'm looking for
the
balance between fast code, but not processor hog.

I discovered that DELAY PROCESS(Current process;1) consistently
actually
delays 2 to 4 ticks, not just one tick.  So, a loop such as:
Repeat
 `Do Something
 =A0Delay process(current process;1)
Until(someCondition)
... Will only run about 15 times/second compiled.

I've tried the following code, compiled in v12.6, 13.4 and 14.0, and
get
similar results in all:
<Begin Code>
 //Test Method to see how long DELAY PROCESS(Current process;1) really
delays for
$Log_t:=""
$Tickstart_i:=Tickcount
$Count_i:=0
$LastTick_i:=$Tickstart_i
Repeat
DELAY PROCESS(Current process;1)
$Tick_i:=Tickcount
$Log_t:=$Log_t+String(Tickcount)+Char(9)\
+String($Tick_i-$LastTick_i)+Char(13)
$LastTick_i:=$Tick_i
$Count_i:=$Count_i+1
Until ((Tickcount-$Tickstart_i)>60)
$Log_t:="Count: "+String($Count_i)\
+"\rTick\tTickDiff\r"+$Log_t
SET TEXT TO PASTEBOARD($Log_t)
ALERT($Log_t)
<End Code>

Results:
Count: 20
Tick  =A0 TickDiff
36653148  =A0 2
36653152  =A0 4
36653156  =A0 4
36653159  =A0 3
36653163  =A0 4
36653167  =A0 4
36653171  =A0 4
36653174  =A0 3
36653178  =A0 4
36653182  =A0 4
36653186  =A0 4
36653188  =A0 2
36653193  =A0 5
36653195  =A0 2
36653197  =A0 2
36653199  =A0 2
36653201  =A0 2
36653203  =A0 2
36653205  =A0 2
36653207  =A0 2

NOTE 1:
I've attempted to spawn secondary process to un-delay (DELAY
PROCESS(MainProcess;0), in attempts to speed up my listener, to almost
no
benefit.  The most I've been able to achieve is about 30 reps/second,
and
not on well balanced time increments.

If I replace DELAY PROCESS(MyProcess;1) with DELAY
PROCESS(MyProcess;0) ,
then my process cycles about 16million times/second, and becomes a
processor
hog.

NOTE 2: Using SET TIMER in a form has similar performance.

--
Tony Ringsmuth
Business Brothers Inc.
763-420-8686

Reply to this message

Summary created 4/7/14 at 12:36PM by Intellex Corporation

Comments welcome at: feedback@intellexcorp.com