[Jprogramming] Joining lists
Linda A Alvord
lindaalvord at verizon.net
Mon Feb 1 03:27:12 UTC 2016
Is there a standard way to make random trationals?
Linda
-----Original Message-----
From: Programming [mailto:programming-bounces at forums.jsoftware.com] On Behalf Of Henry Rich
Sent: Sunday, January 31, 2016 9:52 PM
To: programming at jsoftware.com
Subject: Re: [Jprogramming] Joining lists
When you throw in a floating-point conversion the fraction of time owing to copying arguments becomes smaller.
Henry Rich
On 1/31/2016 9:38 PM, Jose Mario Quintana wrote:
> "
> The observed ratio of measurements for the two operations, in both
> space and time, is pretty close to (3%5) as we would expect from the above.
> "
>
> It makes sense; yet, what I found interesting was that a measure of
> overall (in)efficiency, the space*time, gain seems different for the two samples:
>
> 1.68731e6 3.33377e6 % 664728 1.81216e6
> 2.53834651 1.83966648
>
>
>
> On Sun, Jan 31, 2016 at 9:08 PM, Marshall Lochbaum
> <mwlochbaum at gmail.com>
> wrote:
>
>> It's not surprising at all if you know a little bit about how the
>> verbs in question work. Dyad (,) creates a new array and copies its
>> arguments into it. Thus computing (a,b,c) requires the steps:
>> - Copy b and c into new array t1 (2e6 copy operations)
>> - Copy a and t1 into new array t2 (3e6 copy operations).
>>
>> In contrast, dyad (;) is almost free, since it just creates an array
>> of pointers to its arguments. Monad (;) computes the length of its
>> result, allocates an array of that length, and then copies everything
>> in, for a total of 3e6 copies. Provided we can't resize a to hold all
>> the values (which would allow us to only copy b and c), this is
>> optimal with J's array layout.
>>
>> The observed ratio of measurements for the two operations, in both
>> space and time, is pretty close to (3%5) as we would expect from the above.
>>
>> Marshall
>>
>> On Sun, Jan 31, 2016 at 08:35:01PM -0500, Jose Mario Quintana wrote:
>>> That is interesting, I was independently testing the same expression
>>> ;A
>> ;
>>> B ; C vs A , B , C with different sample nouns and it seems
>>> leaner and
>>> meaner:
>>>
>>> st=. (, */&.:>@:(1 2&{))@:(] ; 7!:2@:] ; 6!:2)
>>>
>>> 'A B C'=. i.3 1000000
>>>
>>> 111 st&>'A , B , C' ; ';A ; B ; C'
>>> ┌──────────┬────────┬─────────┬─────────┐
>>> │A , B , C │50333184│0.0335228│1.68731e6│
>>> ├──────────┼────────┼─────────┼─────────┤
>>> │;A ; B ; C│33556608│0.0198092│664728 │
>>> └──────────┴────────┴─────────┴─────────┘
>>>
>>> (A , B , C) -: i.3000000
>>> 1
>>> (;A ; B ; C) -: i.3000000
>>> 1
>>>
>>> Using your sample nouns it is not as dominant but remains dominant
>>> nevertheless:
>>>
>>> A=:?~1000000
>>> B=:0.1+?~1000000
>>> C=:?~1000000
>>>
>>> 111 st&>'A , B , C' ; ';A ; B ; C'
>>> ┌──────────┬────────┬─────────┬─────────┐
>>> │A , B , C │67110400│0.0496758│3.33377e6│
>>> ├──────────┼────────┼─────────┼─────────┤
>>> │;A ; B ; C│50333824│0.0360027│1.81216e6│
>>> └──────────┴────────┴─────────┴─────────┘
>>>
>>> (A , B , C) -: (;A ; B ; C)
>>> 1
>>>
>>>
>>> JVERSION
>>> Installer: j602a_win.exe
>>> Engine: j803/2014-10-19-11:11:11
>>> Library: 6.02.023
>>>
>>>
>>>
>>> On Sun, Jan 31, 2016 at 7:05 PM, Raul Miller <rauldmiller at gmail.com>
>> wrote:
>>>> Oops, I meant:
>>>>
>>>> timespacex ';a;b;c'
>>>> 0.012332 5.03338e7
>>>> timespacex ';a;b;c'
>>>> 0.011768 5.03338e7
>>>> (;a;b;c)-:a,b,c
>>>> 1
>>>>
>>>> Efficiency characteristics are the same, result (the most important
>>>> part) is different.
>>>>
>>>> --
>>>> Raul
>>>>
>>>> On Sun, Jan 31, 2016 at 7:04 PM, Raul Miller
>>>> <rauldmiller at gmail.com>
>>>> wrote:
>>>>> If I define:
>>>>> a=:?~1000000
>>>>> b=:0.1+?~1000000
>>>>> c=:?~1000000
>>>>>
>>>>> I get:
>>>>> timespacex 'a,b,c'
>>>>> 0.016585 6.71104e7
>>>>> timespacex '>a;b;c'
>>>>> 0.012863 5.0334e7
>>>>> timespacex '>a;b;c'
>>>>> 0.011867 5.0334e7
>>>>> timespacex 'a,b,c'
>>>>> 0.015703 6.71104e7
>>>>>
>>>>> So it looks like >a;b;c is slightly more efficient than a,b,c, but
>>>>> it's nowhere close to a factor of 2, so I think I'd ignore this
>>>>> issue in most contexts.
>>>>>
>>>>> --
>>>>> Raul
>>>>>
>>>>>
>>>>> On Sun, Jan 31, 2016 at 5:21 PM, Henry Rich <henryhrich at gmail.com>
>>>> wrote:
>>>>>> You have 3 large lists a, b, c (1000000 atoms each). You want to
>> join
>>>> them
>>>>>> into one long list. What is the best way to do this?
>>>>>>
>>>>>> Henry Rich
>>>>>>
>> ---------------------------------------------------------------------
>> -
>>>>>> For information about J forums see
>> http://www.jsoftware.com/forums.htm
>>>> -------------------------------------------------------------------
>>>> --- For information about J forums see
>>>> http://www.jsoftware.com/forums.htm
>>>>
>>> --------------------------------------------------------------------
>>> -- For information about J forums see
>>> http://www.jsoftware.com/forums.htm
>> ---------------------------------------------------------------------
>> - For information about J forums see
>> http://www.jsoftware.com/forums.htm
>>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
More information about the Programming
mailing list