× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Add is faster than multiply.  Even faster is a straight assign.  For a loop
of 500,000 iterations, the milliseconds are shown below.  "None" is for an
empty loop.  Add is about 40% faster than multiple, assign is about 8%
faster than add.

DSPLY  None: 136 Mult: 710 Add: 519 Assign: 481

Here's the code:

d T0              s               z             
d T1              s               z             
d T2              s               z             
d T3              s               z             
d T4              s               z             
                                                
d x               s             10u 0           
d MAX             c                   500000    
                                                
d a               s              3u 0           
d b               s              4s 1 inz(123.5)
                                                
d dnone           s             10u 0           
d dmult           s             10u 0           
d dadd            s             10u 0           
d dasgn           s             10u 0           
                                                 
d msg             s             52               
                                                 
 /free                                           
  t0 = %timestamp();                             
  for x = 1 to MAX;                              
  endfor;                                        
  t1 = %timestamp();                             
  for x = 1 to MAX;                              
    eval(h) a = b * 1;                     
  endfor;                                  
  t2 = %timestamp();                       
  for x = 1 to MAX;                        
    eval(h) a = b + 0;                     
  endfor;                                  
  t3 = %timestamp();                       
  for x = 1 to MAX;                        
    eval(h) a = b;                         
  endfor;                                  
  t4 = %timestamp();                       
                                           
  dnone = %diff( t1: t0: *MSECONDS) / 1000;
  dmult = %diff( t2: t1: *MSECONDS) / 1000;
  dadd  = %diff( t3: t2: *MSECONDS) / 1000;
  dasgn = %diff( t4: t3: *MSECONDS) / 1000;
                                           
                                                                  
  eval msg = 'None: ' + %char(dnone) + ' Mult: ' + %char(dmult) + 
             ' Add: ' + %char(dadd)  + ' Assign: ' + %char(dasgn);
  dsply msg;                                                      
                                                                  
  *inlr = *on;                                                    
 /end-free                                                        


> From: PaulMmn
> 
> What's faster:
> 
>       Eval(H)...  MyField * 1
> 
> or
> 
>       Eval(H)...  MyField + 0



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.