![]() |
Forum Index : Microcontroller and PC projects : CMM2 and timing some simple code.
Author | Message | ||||
KeepIS![]() Guru ![]() Joined: 13/10/2014 Location: AustraliaPosts: 1882 |
CMM2 and timing some code. I was interested in the speed hit between a few of the MMBasic commands. As most likely know, unless the default console option is changed, Print and Print @ output to the USB console port and VGA console screen, however the Text command is more a graphic write to the Console VGA screen only. I timed Text write for x number of strings to the Console screen and Print, with and without the USB console enabled. Print @(x,y) USB Console disable: 776.672ms Print @(x,y) default Console setting: 6000,615ms Text x,y: 722.295ms *** Next: Simplistic code I used for testing: if then elseif compared to 3 separate if then, and a select case. x=0 : i=40000 timer=0 do x=x+1 if x=i then j=j elseif x=i*2 then j=j elseif x=i*3 then exit do endif loop print timer x=0 : timer=0 do x=x+1 if x=i then j=j endif if x=i*2 then j=j endif if x=i*3 then exit do endif loop print timer x=0 : timer=0 do x=x+1 select case x case i j=j case i*2 j=j case i*3 exit do end select loop Print timer if then elseif: 3383.67ms 3 x if then: 3473.181ms Select Case: 2212.352ms **** as expected Next An if then test of two conditions compared to two separate single tests. x=0 : j=1 timer=0 Do x=x+1 if x=i and j then j=j elseif x=i*2 and j then j=j elseif x=i*3 and j then exit do endif loop print timer x=0 timer=0 do x=x+1 if x=i then if j then j=j endif elseif x = i*2 then if j then j=j endif elseif x = i*3 then if j then exit do endif endif loop print timer if x and j : 4239.293 Separate if : 3389.422 *** I purposely use an if-then-endif for the second condition as a number of lines of code could likely be used in that branch condition, not trying to streamline the tests just see which is faster with a large number of iterations. NANO Inverter: Full download - Only Hex Ver 8.1Ks |
||||
JohnS Guru ![]() Joined: 18/11/2011 Location: United KingdomPosts: 4044 |
I'm confused! Your timings - things like 3383.67ms - mean things took seconds?! Do you mean us or what? John |
||||
KeepIS![]() Guru ![]() Joined: 13/10/2014 Location: AustraliaPosts: 1882 |
The loop iteration is 120,000 times, so it's in Ms. . Edited 2020-08-07 18:48 by KeepIS NANO Inverter: Full download - Only Hex Ver 8.1Ks |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10315 |
Your test is simplistic in one important respect. Console I/O is buffered and executes under interrupt control. As long as you don't fill the console output buffer which is 8192 bytes then the overhead of writing to the console is minimal. As soon as the buffer is full then the output rate is determined by the baudrate as the processor stalls waiting for space in the buffer. |
||||
KeepIS![]() Guru ![]() Joined: 13/10/2014 Location: AustraliaPosts: 1882 |
Yes, the console test really should be kept to a lower write value, the console baud rate was 230400. NANO Inverter: Full download - Only Hex Ver 8.1Ks |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |