Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 10:19 25 Nov 2024 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 : Basic speed execution

Author Message
Olimex
Senior Member

Joined: 02/10/2011
Location: Bulgaria
Posts: 226
Posted: 08:38pm 29 Jan 2012
Copy link to clipboard 
Print this post

I downloaded MM3.1 to DM-mini and do the speed test and I see interesting result

Timer = 0
a = 0
10 a = a + 1 : If Timer < 1000 Then 10
? a*3; " instructions per second"

returns 28458 instructions per second
if I split the line 10 in two rows:

Timer = 0
a = 0
10 a = a + 1
If Timer < 1000 Then 10
? a*3; " instructions per second"

then it executes faster and returns 28608 instructions per second
the difference is small but I was expecting code to execute faster if on one line, it's only 0.5 % difference but you could split your code on single lines if you want to speed a little your code execution

I try to write this with labels first but it didn't want to accept label after the THEN and I had to add GOTO label which adds one more command, so I did with number instead

 
darthmite

Senior Member

Joined: 20/11/2011
Location: France
Posts: 240
Posted: 10:40pm 29 Jan 2012
Copy link to clipboard 
Print this post

Hi ,

with no line you can do this


a = 0
Timer = 0
Do While Timer < 1000
a = a + 1
Loop
? a * 3


My MM is packed for my tomorrow travel.
So you can test it for see the speed

Cheers.

Darth.

Theory is when we know everything but nothing work ...
Practice is when everything work but no one know why ;)
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3194
Posted: 10:58pm 29 Jan 2012
Copy link to clipboard 
Print this post

Intriguing.

I tried both code fragments and I got 27804 for the first and 27927 for the second. I looked at the code and I cannot see why one is faster than the other, they should be about the same give or take a few nanoseconds.

BTW, why were my results a little slower? Again I don't know, I ran the test on a prototype DM but there should not be much difference between prototype and production. Perhaps the electrons are slower here (we are in a heatwave).

I also ran the test using labels...
Timer = 0
a = 0
L10: a = a + 1
If Timer < 1000 Then GoTo L10
? a*3; " instructions per second"

And got 29055, 4% faster.

The extra GoTo statement does not add any delay (it is decoded within the IF statement) and the speed increase comes from using a label.

Labels are MUCH faster than line numbers because MMBasic caches the location of labels in the code and can jump straight there rather than search for them. In a big program searching can take a long time and using labels will speed things up by 30%. One user has already reported a 20% speed increase just by converting line numbers to labels.

Geoff
Geoff Graham - http://geoffg.net
 
Juri74

Senior Member

Joined: 06/02/2012
Location: Italy
Posts: 162
Posted: 01:05pm 06 Feb 2012
Copy link to clipboard 
Print this post

  Geoffg said   Intriguing.

I tried both code fragments and I got 27804 for the first and 27927 for the second. I looked at the code and I cannot see why one is faster than the other, they should be about the same give or take a few nanoseconds.

BTW, why were my results a little slower? Again I don't know, I ran the test on a prototype DM but there should not be much difference between prototype and production. Perhaps the electrons are slower here (we are in a heatwave).

I also ran the test using labels...
Timer = 0
a = 0
L10: a = a + 1
If Timer < 1000 Then GoTo L10
? a*3; " instructions per second"

And got 29055, 4% faster.

The extra GoTo statement does not add any delay (it is decoded within the IF statement) and the speed increase comes from using a label.

Labels are MUCH faster than line numbers because MMBasic caches the location of labels in the code and can jump straight there rather than search for them. In a big program searching can take a long time and using labels will speed things up by 30%. One user has already reported a 20% speed increase just by converting line numbers to labels.

Geoff


Hello!
The "a*3" was because 3 basic instructions:
1) a=a+1
2) if then
3) goto

if goto is decoded with if statement and does not add delay then are basic instruction only 2? so a=a*2?

Juri
 
djuqa

Guru

Joined: 23/11/2011
Location: Australia
Posts: 447
Posted: 01:45pm 06 Feb 2012
Copy link to clipboard 
Print this post

All I can say is ,you guys have very little time to spare if a few milliseconds is a concern!

The difference is most likely as a result of the parser not have to having to separate the two parts of the single line version.


And the internal propagation characteristics of signals thruough the PIC32 Die is dependent on a lot of factors. Temperature and voltage are the most critical, but parasitic Inductance, resistance and capacitance affect the speed as well.


Edited by djuqa 2012-02-08
VK4MU MicroController Units

 
YT2095

Newbie

Joined: 07/02/2012
Location: United Kingdom
Posts: 22
Posted: 06:42pm 07 Feb 2012
Copy link to clipboard 
Print this post

in one example the Timer is set to 0, and Then a is set to 0.
in the other A is set first and then the timer is set afterwards.
perhaps the timer is running whilst a is being set to 0?
it would be an idea to keep these consistant and work from that point, maybe even use the CLEAR command instead?

just a thought ;)
 
YT2095

Newbie

Joined: 07/02/2012
Location: United Kingdom
Posts: 22
Posted: 11:08am 12 Feb 2012
Copy link to clipboard 
Print this post

I`v been experimenting with the speed program, to see if cooling the PIC32 makes any difference at all.
and came across something interesting, Cooling seems to make no perceptible difference, but running it on an external 5v PSU, and unplugging the USB lead does give a tiny increase in speed, from 28920 to 28944.
and you get 28866 if you run on Comp Video out, so it seems that VGA is faster.

but there`s a catch!, you have to power up Initially with USB else you`ll get a really slow benchmark of 28251.

that reads to me that on 1`st powerup cylces are being used Looking for some USB activity, when it`s Had that exposure, it still uses cycles for the USB, but much less, and when it`s removed Afterwards, no cylces are being used for usb.
and all things are a bit faster with VGA.

Maybe useful to someone?
 
Print this page


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

© JAQ Software 2024