Data Sheet

dScript
dScript User Manual v2.15
Performance
For those interested in how fast the module executes dScript commands, there is a system
variable (system.DespatchCounter) that counts up by one each time a dScript instruction is
executed. It counts all instructions in all threads so its a system total. The following program
will display the execution speed on an LCD05 module.
A timer thread is set up to read the system.DespatchCounter once per second, reading the
system.DespatchCounter will automatically reset it to zero. Therefore reading it each second
gives the total instructions executed in the last second. A loop in the main thread displays the
count on the LCD05.
If you run this program you may have a bit of a shock. It will say you are executing just 11
instructions per second, why so few?
dScript is a multi-threaded system, and those threads can be suspended (with the
threadsuspend command) or sleeping (with the threadsleep command). There are two threads
running, the Timer1 thread and the do loop in the main thread. The timer thread runs once per
second and has just two instructions. That accounts for 2 of our 11 instructions.
Take a look at the do loop in the main thread. It has two 500mS sleep instructions used to
flash the red led. So this thread also only runs once per second and has 9 instructions The “do”
is not an executable instruction, the compiler just notes its position for the “loop” instruction to
jump back to. In total just 11 instructions need be executed per second. This demonstrates the
power of dScript. By not wasting CPU time running around endless loops waiting for something
to happen, the CPU is available on demand when an event calls for service.
So how fast can it go?
To load the CPU to its maximum we need a thread that does not suspend or sleep, that just
keeps running forever. Notice that we have a thread called “AlwaysRunning” but its threadstart
command is currently commented out, so its not actually running yet. Remove the comment
and load the program again. Now you will see a massive increase in speed, on a dS3484 it will
show over 50,000 instructions/second. That is running two reasonably complex calculation
instructions in the “AlwaysRunning” Thread, both of which includes an analogue to digital
conversion, and the loop instruction to do it again.
Now comment out the two calculation instructions just leaving an empty do-loop and run the
program again. This time you will see around 476,000 instructions/second.
A real program will contain a mix of complex and simple instructions and 100,000 to 200,000
is a reasonable expectation, however it does depend on the program. You can put your own
mix of instructions within the do-loop and see what you get.
Copyright © 2016, Devantech Ltd.
All rights reserved.
www.robot-electronics.co.uk
55