Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 18:49 30 Sep 2022 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : CMM2 vs. PicoMite 2 Mio For-Next-Benchmark

Author Message
andreas

Regular Member

Joined: 07/12/2020
Location: Germany
Posts: 95
Posted: 08:47am 23 Sep 2022
Copy link to clipboard 
Print this post

2 Mio For..Next Loops

CMM2:



PicoMiteVGA:




The CMM2 (480MHz) is 8.3 times faster than the PicoMiteVGA (126MHz)

The CMM2 has an #include-statement which enables modular software.

-andreas
 
Martin H.

Regular Member

Joined: 04/06/2022
Location: Germany
Posts: 76
Posted: 09:37am 23 Sep 2022
Copy link to clipboard 
Print this post


Messung von 2000000 For-Next - Statents
----------------------------------------
Pro Sekunde:      268592
Gesamtlaufzeit:   7.446217
> option list
OPTION KEYBOARD GR
OPTION CPUSPEED (KHz) 378000
OPTION SDCARD GP10, GP12, GP11, GP13
OPTION AUDIO GP6,GP7, ON PWM CHANNEL 3

with OPTION CPUSPEED 378000
~ half as fast as cmm2


Print "Messung von 2000000 For-Next - Statents"
Print "----------------------------------------"
t%=Timer
For f%=1 To 2000000
Next f%
l= Timer-t%
Print "Pro Sekunde:     ";Int(2000000/(l/1000))
Print "Gesamtlaufzeit:  "l /1000




a littlie faster, if I put the Next statement in the same Line as the For Statement :

Messung von 2000000 For-Next - Statents
----------------------------------------
Pro Sekunde:      275513
Gesamtlaufzeit:   7.259177

but .. if I delete the Variable behind the NEXT Statement

Messung von 2000000 For-Next - Statents
----------------------------------------
Pro Sekunde:      589522
Gesamtlaufzeit:   3.392575
 

Print "Messung von 2000000 For-Next - Statents"
Print "----------------------------------------"
t%=Timer
For f%=1 To 2000000:Next
l= Timer-t%
Print "Pro Sekunde:     ";Int(2000000/(l/1000))
Print "Gesamtlaufzeit:  "l /1000



the question remains, how meaningful such test results are
Cheers
Mart!n
Edited 2022-09-23 19:59 by Martin H.
'no comment
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 674
Posted: 12:47pm 23 Sep 2022
Copy link to clipboard 
Print this post

As an experiment to see how fast a Pico can read a pin in a FOR - NEXT loop I wrote a program to read a DHT11 temp / humidity sensor and found you can fill an array at 15uS per sample.

CPUSPEED = 378000 kHz, a one digit pin number and all on one line. Every character slows it down.
Here is the relevant part.

'Data format - 80uS high start pulse, 50uS low + 25uS high = 0, 50uS low + 70uS high = 1
Dim integer n
' deliver 20 mS pulse to wake up DHT11
 SetPin 1,dout,oc
 Pin(1)=1
 Pulse 1,20
 Pause 19
 SetPin 1,off
 SetPin 1,din 'Get the samples
 For n=0 To 329:a(n)=Pin(1):Next
 SetPin 1, off  'Got the samples
'for max. speed the above 'for-next' must be on one line with fewest characters

Edited 2022-09-24 09:01 by phil99
 
andreas

Regular Member

Joined: 07/12/2020
Location: Germany
Posts: 95
Posted: 07:41pm 25 Sep 2022
Copy link to clipboard 
Print this post

  phil99 said  As an experiment to see how fast a Pico can read a pin in a FOR - NEXT loop I wrote a program to read a DHT11 temp / humidity sensor and found you can fill an array at 15uS per sample.

CPUSPEED = 378000 kHz, a one digit pin number and all on one line. Every character slows it down.
Here is the relevant part.

'Data format - 80uS high start pulse, 50uS low + 25uS high = 0, 50uS low + 70uS high = 1
Dim integer n
' deliver 20 mS pulse to wake up DHT11
 SetPin 1,dout,oc
 Pin(1)=1
 Pulse 1,20
 Pause 19
 SetPin 1,off
 SetPin 1,din 'Get the samples
 For n=0 To 329:a(n)=Pin(1):Next
 SetPin 1, off  'Got the samples
'for max. speed the above 'for-next' must be on one line with fewest characters


Very interesting! So one can sample more than 1/15uS = 66666 samples a seconds using for-next on a pico.  

-andreas
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 1649
Posted: 07:57pm 25 Sep 2022
Copy link to clipboard 
Print this post

And 32000000 times per seond using the PIO.
If nothing goes right ... turn left
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 674
Posted: 11:36pm 25 Sep 2022
Copy link to clipboard 
Print this post

"And 32000000 times per second using the PIO."

Yes indeed, if you have A Need for Speed.

ADC and CSUB LOG also work well.

Update on the For - Next. The 15uS per sample was before I added
Dim Integer n
That reduced it to 12.4uS per sample = 80,645 samples / second.
I had assumed, wrongly, that the counter in a For - Next would automatically be an integer.
That enables it to catch the 25uS pulses at 252MHz most of the time.
 
Tinine
Guru

Joined: 30/03/2016
Location: United Kingdom
Posts: 1439
Posted: 04:06am 26 Sep 2022
Copy link to clipboard 
Print this post

  andreas said  

The CMM2 has an #include-statement which enables modular software.

-andreas


Because it runs from SD?



Craig
 
Tinine
Guru

Joined: 30/03/2016
Location: United Kingdom
Posts: 1439
Posted: 04:09am 26 Sep 2022
Copy link to clipboard 
Print this post

  phil99 said  "And 32000000 times per second using the PIO."

Yes indeed, if you have A Need for Speed.

ADC and CSUB LOG also work well.

Update on the For - Next. The 15uS per sample was before I added
Dim Integer n
That reduced it to 12.4uS per sample = 80,645 samples / second.
I had assumed, wrongly, that the counter in a For - Next would automatically be an integer.
That enables it to catch the 25uS pulses at 252MHz most of the time.


Doesn't a decrementing For-Next run even faster?


Craig
 
Tinine
Guru

Joined: 30/03/2016
Location: United Kingdom
Posts: 1439
Posted: 06:56am 26 Sep 2022
Copy link to clipboard 
Print this post

For decades, I have been using a high-end industrial controller (read:expensive) which consists of a real-time back-end and an extemely crude BASIC-like interpreter on the front-end.

This interpreter has one data-type which is float. A literal string can be produced using a 2-character mnemonic MG"Hello World" (MG = message).

I have been able to achieve all I need with this language and I never wondered about execution speed because it's never been a concern.
I spent yesterday going through their documentation and the same for other similar high-end products and heck, PMBasic totally blows them out of the water. Turns out that the product I was using ten years ago which I regarded as stupidly fast, has a command execution time of 400uS  
Then I moved-on to a newer model that boasted "10 times faster"...40uS...What's that, a MMBasic PIC32MX170 @40MHz?  
Their flagship is 11uS and that would cost me close to £4K

Another big-name alternative ($4.4K Used on eBay) cautions about the limitations of their 32bits and single precision. Also runs @ ~25,000 lines/sec.


MMBasic just totally freaking ROCKS!!!

Craig
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 674
Posted: 08:04am 26 Sep 2022
Copy link to clipboard 
Print this post

"Doesn't a decrementing For-Next run even faster?"

I must try it.
Now that you have jogged my decrepit memory I may have done that in the past.
 
Plasmamac

Guru

Joined: 31/01/2019
Location: Germany
Posts: 319
Posted: 09:11am 26 Sep 2022
Copy link to clipboard 
Print this post

@andreas where can i find the pcb from your Picomite?
Plasma
 
Martin H.

Regular Member

Joined: 04/06/2022
Location: Germany
Posts: 76
Posted: 12:45pm 26 Sep 2022
Copy link to clipboard 
Print this post

  Tinine said  

Doesn't a decrementing For-Next run even faster?


Craig


hmm no


Print "Messung von 2000000 For-Next - Statents"
Print "----------------------------------------"
t%=Timer
For f%=2000000 To 1 Step -1:Next
l= Timer-t%
Print "Pro Sekunde:     ";Int(2000000/(l/1000))
Print "Gesamtlaufzeit:  "l /1000
>

Messung von 2000000 For-Next - Statents
----------------------------------------
Pro Sekunde:      583799
Gesamtlaufzeit:   3.425835

Cheers
Mart!n
'no comment
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 674
Posted: 12:56pm 26 Sep 2022
Copy link to clipboard 
Print this post

"Doesn't a decrementing For-Next run even faster?"

"hmm no"
Got the same result. What little gain there might have been was offset by the extra characters STEP -1
 
andreas

Regular Member

Joined: 07/12/2020
Location: Germany
Posts: 95
Posted: 02:30pm 26 Sep 2022
Copy link to clipboard 
Print this post

  Tinine said  
  andreas said  

The CMM2 has an #include-statement which enables modular software.

-andreas


Because it runs from SD?



Craig


Yes, the CMM2 has a SD-Card. But the picos can have a sd-card also. If one uses a pico as data logger, educational hardware, game machine, hobbyist thing - it makes sense to have a mass storage.

#include in MMBASIC is the same as a definition/implementation module in Modula-2 or a DLL in Windows or a word in FORTH. You need it if you want to write code only once for a certain task and create more and more complex software out of simple building blocks.

-andreas
 
andreas

Regular Member

Joined: 07/12/2020
Location: Germany
Posts: 95
Posted: 02:42pm 26 Sep 2022
Copy link to clipboard 
Print this post

  Plasmamac said  @andreas where can i find the pcb from your Picomite?


Hi Plasma, do you mean this one?



This is from Silicon Chip magazin July 22 VGA PicoMite ($5) or Kit ($35).

-andreas
 
andreas

Regular Member

Joined: 07/12/2020
Location: Germany
Posts: 95
Posted: 03:14pm 26 Sep 2022
Copy link to clipboard 
Print this post

Don't ask me what is going on here - this version does it in a second!

Can someone verify this? I'm curious where the mistake is - but this seems to be too fast, isn't it?



' speed.bas - Laufzeitmessung
'
CLS
CONST Maxloop = 2000000        ' Anzahl der Loops

DIM Laufzeit AS FLOAT = 0.0    ' in Sekunden
DIM a AS INTEGER = 0           ' Dummy
DIM T1 AS INTEGER = 0
DIM T2 AS INTEGER = 0          ' Timer in Millisekunden

PRINT
PRINT "Messung von ";Maxloop%;" For-Next - Statements"
PRINT "------------------------------------------"
PRINT

T1 = timer

for a = 1 to Maxloop:next

T2 = timer

Laufzeit = (T2 - T1)/1000.0

PRINT "Pro Sekunde:    ";INT(Maxloop/Laufzeit);" Iterationen"
PRINT "Gesamtlaufzeit: ";Laufzeit;" Sekunden"
save image "cmm2.bmp"


The CMM2 is not "tuned" it simply runs @ 480MHz.
-andreas
 
andreas

Regular Member

Joined: 07/12/2020
Location: Germany
Posts: 95
Posted: 06:15pm 26 Sep 2022
Copy link to clipboard 
Print this post

Using the same code on the PicoMiteVGA (simply by using the same sd-card) I get improved values:



By comparing the old benchmark code to the current code there is one major difference: In the new faster code I did declare the control variable as integer before use within the for..next construct.

Result: Declaring control variables before use results in huge speed-up!

Example:

CONST Maxloop = 10000000    
DIM i AS INTEGER = 0        ' gives huge speed-up

FOR i = 1 to Maxloop

 'Do_something

NEXT                        ' do not write i after NEXT


It seem to be very important not to write down the control variable after the next-statement.

Writing: for i = 1 to Maxloop : next  

is much faster than

writing: for i = 1 to Maxloop : next i

Doing real measurements on the cmm2 within the for..next loop:



' bench.bas - how fast can you measure

const maxmeasure = 500000 ' number of measurements
cls
dim mess(maxmeasure) as integer
dim i as integer = 0
setpin 33,din ' digital input on pin 33

print "Start... ";
t1 = timer

for i = 1 to maxmeasure: mess(i) = pin(33):next

diff=timer-t1

print diff;" ms for ";maxmeasure;" measurements"
print
print (maxmeasure/diff)*1000;" measurements per second"
print

memory

save image "camac.bmp"



-andreas
Edited 2022-09-27 06:46 by andreas
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2022