Special code seems to be involved because usually replacing  2&|  by  2 | ]
 should not make much difference in performance but it makes a difference
in this case:

   Cut=. -.&a: @: (<;._2@,~)
   st=. (, */&.:>@:(1 2&{))@:(] ; 7!:2@:] ; 6!:2)
   stp2=. [ ((;:'Sentence Space Time Product') , st&>) LF Cut ]

   stp=. 1&stp2 : stp2 f.

   I=. i.100000

   11 stp noun define
       +:^:(2&|  )"0 I
       +:^:(2 | ])"0 I
     ]`+:@.(2&|  )"0 I
     ]`+:@.(2 | ])"0 I
)
┌──────────────────────┬───────┬──────────┬───────┐
│Sentence              │Space  │Time      │Product│
├──────────────────────┼───────┼──────────┼───────┤
│       +:^:(2&|  )"0 I│1052160│0.046733  │49170.6│
├──────────────────────┼───────┼──────────┼───────┤
│       +:^:(2 | ])"0 I│1052160│0.0580962 │61126.5│
├──────────────────────┼───────┼──────────┼───────┤
│     ]`+:@.(2&|  )"0 I│6032768│0.00553589│33396.8│
├──────────────────────┼───────┼──────────┼───────┤
│     ]`+:@.(2 | ])"0 I│6033280│0.0204798 │123560 │
└──────────────────────┴───────┴──────────┴───────┘

Notice also,

   11 stp noun define
           (2&|  )"0 I
           (2 | ])"0 I
)
┌──────────────────────┬──────┬───────────┬───────┐
│Sentence              │Space │Time       │Product│
├──────────────────────┼──────┼───────────┼───────┤
│           (2&|  )"0 I│133504│0.000196446│26.2264│
├──────────────────────┼──────┼───────────┼───────┤
│           (2 | ])"0 I│133888│0.0142925  │1913.59│
└──────────────────────┴──────┴───────────┴───────┘

versus

   11 stp noun define
           (2&|  )   I
           (2 | ])   I
)
┌──────────────────────┬──────┬───────────┬───────┐
│Sentence              │Space │Time       │Product│
├──────────────────────┼──────┼───────────┼───────┤
│           (2&|  )   I│132864│0.000195543│25.9807│
├──────────────────────┼──────┼───────────┼───────┤
│           (2 | ])   I│132864│0.000195243│25.9407│
└──────────────────────┴──────┴───────────┴───────┘

The following is a summary of the performance of the solutions suggested so
far including the  2 | ]  variants:

   11 stp noun define
       +:^:(2&|  )"0 I  NB. Pascal
       +:^:(2 | ])"0 I  NB. Pascal
     ]`+:@.(2&|  )"0 I  NB. Pascal
     ]`+:@.(2 | ])"0 I  NB. Pascal
     (* 1 + 2&|  )   I  NB. Dan
     (* 1 + 2 | ])   I  NB. Dan
(32 b.~ 1&(17 b.))   I  NB. Henry
)
┌────────────────────────────────────┬───────┬──────────┬───────┐
│Sentence                            │Space  │Time      │Product│
├────────────────────────────────────┼───────┼──────────┼───────┤
│       +:^:(2&|  )"0 I  NB. Pascal  │1052672│0.0490038 │51585  │
├────────────────────────────────────┼───────┼──────────┼───────┤
│       +:^:(2 | ])"0 I  NB. Pascal  │1052672│0.055311  │58224.4│
├────────────────────────────────────┼───────┼──────────┼───────┤
│     ]`+:@.(2&|  )"0 I  NB. Pascal  │6033280│0.00488106│29448.8│
├────────────────────────────────────┼───────┼──────────┼───────┤
│     ]`+:@.(2 | ])"0 I  NB. Pascal  │6033792│0.0199239 │120216 │
├────────────────────────────────────┼───────┼──────────┼───────┤
│     (* 1 + 2&|  )   I  NB. Dan     │2100096│0.00116601│2448.73│
├────────────────────────────────────┼───────┼──────────┼───────┤
│     (* 1 + 2 | ])   I  NB. Dan     │2100096│0.00116002│2436.15│
├────────────────────────────────────┼───────┼──────────┼───────┤
│(32 b.~ 1&(17 b.))   I  NB. Henry   │2100992│0.00107981│2268.67│
└────────────────────────────────────┴───────┴──────────┴───────┘

(Notice also the extra space used due to the NB.)

This is a clean version of the script:

Cut=. -.&a: @: (<;._2@,~)
st=. (, */&.:>@:(1 2&{))@:(] ; 7!:2@:] ; 6!:2)
stp2=. [ ((;:'Sentence Space Time Product') , st&>) LF Cut ]

stp=. 1&stp2 : stp2 f.

I=. i.100000

11 stp noun define
       +:^:(2&|  )"0 I
       +:^:(2 | ])"0 I
     ]`+:@.(2&|  )"0 I
     ]`+:@.(2 | ])"0 I
)


11 stp noun define
           (2&|  )"0 I
           (2 | ])"0 I
)

11 stp noun define
           (2&|  )   I
           (2 | ])   I
)


11 stp noun define
       +:^:(2&|  )"0 I  NB. Pascal
       +:^:(2 | ])"0 I  NB. Pascal
     ]`+:@.(2&|  )"0 I  NB. Pascal
     ]`+:@.(2 | ])"0 I  NB. Pascal
     (* 1 + 2&|  )   I  NB. Dan
     (* 1 + 2 | ])   I  NB. Dan
(32 b.~ 1&(17 b.))   I  NB. Henry
)


On Mon, Dec 28, 2015 at 1:48 PM, 'Pascal Jasmin' via Programming <
[email protected]> wrote:

>     timespacex '+:^:(2&|)"0 i.100000'
> 0.0292787 2.10074e6
>   timespacex ']`+:@.(2&|)"0 i.100000'
> 0.00561727 7.08134e6
>
> above code doubles odd numbers, and returns even numbers unchanged.
>
>
> I've previously noticed that ^: seemd faster than ]`u@. ... but I guess
> not?
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to