performance with integers

General APL language issues
Post Reply
User avatar
giangiquario
Posts: 46
Joined: Thu Nov 26, 2009 8:55 am
Location: Milano, Italia

performance with integers

Post by giangiquario »

I am looking forward performance in my code.

I met a situation that I cannot explain to myself.
Please look at following code:

Code: Select all

       m2←9999 9⍴⍳999
       m1←9999 9⍴⍳999 ⋄ m1[;4]←1.2

           ⍝ I can explain next comparison
 
      cmpx '{m1[;4]←1.12 ⋄ 0}⍬ ' '{m2[;4]←1025⋄ 0}⍬'
  {m1[;4]←1.12 ⋄ 0}⍬  3.7E¯5   0% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
  {m2[;4]←1025⋄ 0}⍬   1.3E¯5 -67% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕     
                     

           ⍝ but I cannot explain next comparison

      cmpx '{m1[;4]←1.3 ⋄ 0}⍬ ' '{m2[;4]←12⋄ 0}⍬'
  {m1[;4]←1.3 ⋄ 0}⍬  3.6E¯5    0% ⎕⎕⎕⎕⎕⎕                                 
  {m2[;4]←12⋄ 0}⍬    2.5E¯4 +577% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕



Thanks for any hint.
JohnS|Dyalog

Re: performance with integers

Post by JohnS|Dyalog »

Hi Gianluigi:
This effect is caused by an optimisation if the replacement value is of the same ⎕DR type as the array into which it is being assigned.
As you point out, if the ⎕DR types differ, this optimisation is skipped. Here is a simple example:

      )copy dfns cmpx
... saved ...
imat←9999 9⍴⍳999 ⍝ 2-byte-integer matrix
cmpx'imat[;4]←127' 'imat[;4]←128' ⍝ 1-byte vs 2-byte replacement
imat[;4]←127 → 9.5E¯4 | 0% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
* imat[;4]←128 → 9.4E¯5 | -91% ⎕⎕⎕⎕

I have logged a request for a performance improvement:
[8617] Indexed assignment of narrower item type should be optimised.
Thanks for taking the time to report this,
John.
Post Reply