Order of operators

Jim Bufalini jim at visitrieve.com
Thu Aug 27 11:05:45 EDT 2009


Hey Mark,

Your question peaked my curiosity because I use brackets for everything
(never hundreds of pairs) ;-) and why I threw out an answer. Anyway, I just
ran 10,000 iterations of the following three calculations. The first two
arrive at the same answer and the third one doesn't, of course, but has no
brackets.

((((1*2)+3)-4)/5)^6
((1*2+3-4)/5)^6
1*2+3-4/5^6

I could find no significant millisecond difference between the three. Each
of the 10,000 iterations could vary by 1 to 2 milliseconds, but I suspect
this has to do with other things happening on the machine, as they ran at
the same speed when run immediately after each other.

I'd be curious what you find with your hundreds of params. 

Have fun!

Aloha from Hawaii,

Jim Bufalini

> -----Original Message-----
> From: use-revolution-bounces at lists.runrev.com [mailto:use-revolution-
> bounces at lists.runrev.com] On Behalf Of Mark Schonewille
> Sent: Thursday, August 27, 2009 4:18 AM
> To: How to use Revolution
> Subject: Re: Order of operators
> 
> Hi Jim,
> 
> This is about a calculation with potentially hundreds of parameters. I
> don't think that parsing the formula to reduce the number of brackets
> will be fast enough to make the exercise worthwhile.
> 
> I'm building up the formula in a repeat loop, one operator at a time:
> 
> 1
> 1*2
> 1*2+3
> etc.
> 
> I can leave brackets out when a + or - is added, but I wish I could
> leave them all out. I assume a calculation without brackets is faster,
> because the symbols between brackets are parsed first.
> 
> --
> Best regards,
> 
> Mark Schonewille
> 
> Economy-x-Talk Consulting and Software Engineering
> http://economy-x-talk.com
> 
> Download Snapper Screen Recorder at http://snapper.economy-x-talk.com
> 
> On 27 aug 2009, at 15:55, Jim Bufalini wrote:
> 
> > Not sure about no brackets without multiple puts into vars (which
> > should add
> > time), but for less brackets:
> >
> > put ((1*2+3-4)/5)^6
> >
> > Answer is the same due to brackets, precedence of operators (*
> > before +) and
> > left to right calculation (+ before -).
> >
> > But, I'm curious. How much time do brackets add? It's something I
> > never
> > thought of.
> >
> > Aloha from Hawaii,
> >
> > Jim Bufalini
> 
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution




More information about the use-livecode mailing list