Forum Index
HomeZBasic Home   Forum RulesForum Rules   Forum FAQForum FAQ   MemberlistMemberlist   UsergroupsUsergroups   RSS FeedRSS Feed
Site SearchSite Search   LinksLinks   DownloadDownload   Digests and SubscriptionsDigests and Subscriptions
ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in   RegisterRegister
ZX-24 Execution Speed

 
Post new topic   Reply to topic    Forum Index -> ZX-24
Author Message
zbasicandy



Joined: 26 Jan 2006
Posts: 193

Posted: 26 January 2006, 15:58 PM    Post subject: ZX-24 Execution Speed Reply with quote

B = B + 1 is the instruction reference so how is the execution speed computed on the ZX-24?
Is there a project/program via timers which computes this speed?
If so, could you show it on the forum or explain how this number
is computed.
Back to top
dkinzer
Site Admin


Joined: 03 Sep 2005
Posts: 2499
Location: Portland, OR

Posted: 26 January 2006, 17:29 PM    Post subject: Reply with quote

There is no built-in mechanism for measuring or computing instruction timing but it can be measured fairly simply. Consider this code:
Code:
Sub Main()
   Call PutPin(C.0, zxOutputLow)
   Do
      Register.PortC = Register.PortC Xor &H01
   Loop
End Sub


If you connect an oscilloscope or logic analyzer probe to pin 12 and run this program you'll see a square wave whose period is twice the cycle time of the loop. With this basic framework, the execution time of any code sequence can be measured by placing it in the loop and observing the change in the period of the generated waveform. For example:

Code:
Dim b as Byte
Sub Main()
   Call PutPin(C.0, zxOutputLow)
   Do
      b = b + 1
      Register.PortC = Register.PortC Xor &H01
   Loop
End Sub


If everything else is the same, the increase in the period of the generated waveform will be twice the execution time of the added instruction(s).

If you don't have access to an oscilloscope, logic analyzer, frequency counter or similar instrument you can still get a reasonable estimate of the execution time by using a variant of this technique. Firstly, create a framework for testing some code:
Code:
Const cycles as Integer = 1000
Sub Main()
   Dim i as Integer
   Dim t0 as Long
   Dim t1 as Long
   Dim s as String

   t0 = Register.RTCTick
   For i = 1 to cycles
      ' add code to be timed here
   Next i
   t1 = Register.RTCTick

   s = Fmt(CSng(t1 - t0) / 512.0 / CSng(cycles) * 1e6, 3)
   Debug.Print "Execution time is "; s; " microseconds"
End Sub


Run this code and note the reported result. Then add some test code to the loop:

Code:
Const cycles as Integer = 1000
Dim b as Byte
Sub Main()
   Dim i as Integer
   Dim t0 as Long
   Dim t1 as Long
   Dim s as String

   t0 = Register.RTCTick
   For i = 1 to cycles
      b = b + 1
   Next i
   t1 = Register.RTCTick

   s = Fmt(CSng(t1 - t0) / 512.0 / CSng(cycles) * 1e6, 3)
   Debug.Print "Execution time is "; s; " microseconds"
End Sub


Run the modified code and subtract the two reported times. The difference is attributable to the execution time of the added instruction(s).

Depending on how much code you're timing, you might want to modify the cycle count and/or the scaling of the time. Longer execution times might be better reported in milliseconds or seconds for example.


Last edited by dkinzer on 26 January 2006, 21:51 PM; edited 2 times in total
Back to top
spamiam



Joined: 13 Nov 2005
Posts: 665

Posted: 26 January 2006, 17:56 PM    Post subject: Re: ZX-24 Execution Speed Reply with quote

I think that it was times by looping a jillion times, and measuring the elapsed time. I doubt it was with one of the AVR timers directly, instead, I think it used one of the ZBasic register real time clocks. You compare that to the same loop without the measured operation.

Also, you can measure the output of a pin on an oscilloscope and determine timing that way too.

-Tony
Back to top
spamiam



Joined: 13 Nov 2005
Posts: 665

Posted: 26 January 2006, 17:59 PM    Post subject: Re: ZX-24 Execution Speed Reply with quote

spamiam wrote:
I think that it was times by looping a jillion times, and measuring the elapsed time. I doubt it was with one of the AVR timers directly, instead, I think it used one of the ZBasic register real time clocks. You compare that to the same loop without the measured operation.

Also, you can measure the output of a pin on an oscilloscope and determine timing that way too.

-Tony



oops, Don got his better answer in while I was writing mine!!!!

-Tony
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Forum Index -> ZX-24 Time synchro. with the server - Timezone/DST with your computer
Page 1 of 1

 


All content Copyright © 2005-2012 Elba Corp. All Rights Reserved.
Opinions expressed in posts are those of the author and not necessarily those of Elba Corp.
Powered by phpBB © 2001, 2005 phpBB Group