BBC BASIC for Windows
« MOD vs AND »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 10:53pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

If you require a dump of the post on your message board, please come to the support board and request it.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: MOD vs AND  (Read 544 times)
Matt
Developer

member is offline

Avatar




PM

Gender: Male
Posts: 210
xx MOD vs AND
« Thread started on: Oct 10th, 2014, 4:51pm »

Hi,

Just curious.

I know there's a technical difference, but is there a significant speed difference between the use of MOD and AND? The rudimentary test below indicates a slight speed drop when using AND.

Code:
      T% = TIME
      FOR I% = 0 TO &FFFFFF
        A% = I% MOD &10000
      NEXT
      PRINT TIME - T%

      T% = TIME
      FOR I% = 0 TO &FFFFFF
        B% = I% AND &FFFF
      NEXT
      PRINT TIME - T%
 

When using binary related figures, such as in the case above, is there a specific advantage to using AND rather than MOD? Many times in the illustation programs and code snipits from the various helps, I find that AND is used, where MOD might be used. Is this just common practice?

Matt
User IP Logged

rtr2
Guest
xx Re: MOD vs AND
« Reply #1 on: Oct 10th, 2014, 5:31pm »

on Oct 10th, 2014, 4:51pm, Matt wrote:
is there a significant speed difference between the use of MOD and AND? The rudimentary test below indicates a slight speed drop when using AND.

You seem to have answered your own question: you measured a "slight" difference; whether "slight" is "significant" depends on the circumstances, but I would say usually not.

Quote:
Many times in the illustation programs and code snipits from the various helps, I find that AND is used, where MOD might be used. Is this just common practice?

I would speculate that it's because on some older platforms which don't have a native division instruction, like the BBC Micro or BBC BASIC (Z80), you might expect MOD to be quite a lot slower than AND.

Richard.
User IP Logged

Matt
Developer

member is offline

Avatar




PM

Gender: Male
Posts: 210
xx Re: MOD vs AND
« Reply #2 on: Oct 10th, 2014, 6:51pm »

Thanks, Richard.
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls