Re: Ruby List

Hi

No, there is just Array, which is a list.

Maybe there are some gems providing real arrays.

Opti

Just out of curiosity, what benefits are you looking for that aren't
already in Ruby's implementation of an Array?

Edward

···

On 13.01.22 09:57, Die Optimisten wrote:

Hi

No, there is just Array, which is a list.

Maybe there are some gems providing real arrays.

Opti

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<ruby-talk list: member options login page>

--
Freundliche Grüsse

Edward Caulfield

Random access to Array is o(1), while to List is o(n).
Please see this article:

Python by default has no Array too, but Array exists in its Numpy library.

ありがとう
えりな

···

On Thu, Jan 13, 2022 at 6:04 PM Edward <edward.caulfield@gmx.ch> wrote:

Just out of curiosity, what benefits are you looking for that aren't
already in Ruby's implementation of an Array?

Edward

On 13.01.22 09:57, Die Optimisten wrote:
> Hi
>
> No, there is just Array, which is a list.
>
> Maybe there are some gems providing real arrays.
>
> Opti
>
>
>
> Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org
?subject=unsubscribe>
> <ruby-talk list: member options login page>

--
Freundliche Grüsse

Edward Caulfield

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<ruby-talk list: member options login page>

A developer from Scala group says, "never use Array unless you know what
you are doing exactly".
List is suitable for 99% of jobs IMO. But sometimes we do need a high
performance computing library.

ありがとう
えりな

···

On Thu, Jan 13, 2022 at 6:19 PM Yamadaえりな <yamoerina@gmail.com> wrote:

Random access to Array is o(1), while to List is o(n).
Please see this article:
Lists Part III: Lists vs Arrays. Data Structures in Ruby | by D. L. Jerome | Medium

Python by default has no Array too, but Array exists in its Numpy library.

ありがとう
えりな

On Thu, Jan 13, 2022 at 6:04 PM Edward <edward.caulfield@gmx.ch> wrote:

Just out of curiosity, what benefits are you looking for that aren't
already in Ruby's implementation of an Array?

Edward

On 13.01.22 09:57, Die Optimisten wrote:
> Hi
>
> No, there is just Array, which is a list.
>
> Maybe there are some gems providing real arrays.
>
> Opti
>
>
>
> Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org
?subject=unsubscribe>
> <ruby-talk list: member options login page>

--
Freundliche Grüsse

Edward Caulfield

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<ruby-talk list: member options login page>

Benchmarks say Array access is O(1):

3.1.0 :156 > array_1k = Array.new(1000,0)
=>
[0,
...
3.1.0 :157 > puts Benchmark.measure { 1_000_000.times { |n|
array_1k[rand*1_000] } }
  0.218302 0.000000 0.218302 ( 0.218310)
=> nil
3.1.0 :158 > puts Benchmark.measure { 1_000_000.times { |n|
array_1k[rand*1_000] } }
  0.235638 0.000000 0.235638 ( 0.235650)
=> nil
3.1.0 :159 > array_100k = Array.new(100000,0)
=>
[0,
...
3.1.0 :160 > puts Benchmark.measure { 1_000_000.times { |n|
array_100k[rand*100_000] } }
  0.213250 0.000000 0.213250 ( 0.213260)
=> nil
3.1.0 :161 > puts Benchmark.measure { 1_000_000.times { |n|
array_100k[rand*100_000] } }
  0.204273 0.000000 0.204273 ( 0.204281)
=> nil
3.1.0 :162 > puts Benchmark.measure { 1_000_000.times { |n|
array_100k[rand*100_000] } }
  0.224937 0.000000 0.224937 ( 0.225697)
=> nil

Source says it's an array:

<goog_628926836>

/**
* Pointer to the C array that holds the elements of the array. In
* the old days each array had dedicated memory regions. That is
* no longer true today, but there still are arrays of such
* properties. This field could be used to point such things.
*/
const VALUE *ptr;

It may be different for other Ruby implementations.

The sizing of a dynamic array is an exercise in trade-offs. If you have
large amounts of in-memory data and specific performance requirements,
benchmark high perf libraries for your situation.

-gf-

···

On Thu, Jan 13, 2022 at 5:22 AM Yamadaえりな <yamoerina@gmail.com> wrote:

A developer from Scala group says, "never use Array unless you know what
you are doing exactly".
List is suitable for 99% of jobs IMO. But sometimes we do need a high
performance computing library.

ありがとう
えりな

On Thu, Jan 13, 2022 at 6:19 PM Yamadaえりな <yamoerina@gmail.com> wrote:

Random access to Array is o(1), while to List is o(n).
Please see this article:
Lists Part III: Lists vs Arrays. Data Structures in Ruby | by D. L. Jerome | Medium

Python by default has no Array too, but Array exists in its Numpy library.

ありがとう
えりな

On Thu, Jan 13, 2022 at 6:04 PM Edward <edward.caulfield@gmx.ch> wrote:

Just out of curiosity, what benefits are you looking for that aren't
already in Ruby's implementation of an Array?

Edward

On 13.01.22 09:57, Die Optimisten wrote:
> Hi
>
> No, there is just Array, which is a list.
>
> Maybe there are some gems providing real arrays.
>
> Opti
>
>
>
> Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org
?subject=unsubscribe>
> <ruby-talk list: member options login page>

--
Freundliche Grüsse

Edward Caulfield

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org
?subject=unsubscribe>
<ruby-talk list: member options login page>

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<ruby-talk list: member options login page>

Thank you for the benchmark and the document. Glad to see the results.
I will take time to test it on my end.

ありがとう
えりな

···

On Fri, Jan 14, 2022 at 1:41 AM Gerard Fowley <gerard.fowley@iqeo.net> wrote:

Benchmarks say Array access is O(1):

3.1.0 :156 > array_1k = Array.new(1000,0)
=>
[0,
...
3.1.0 :157 > puts Benchmark.measure { 1_000_000.times { |n|
array_1k[rand*1_000] } }
  0.218302 0.000000 0.218302 ( 0.218310)
=> nil
3.1.0 :158 > puts Benchmark.measure { 1_000_000.times { |n|
array_1k[rand*1_000] } }
  0.235638 0.000000 0.235638 ( 0.235650)
=> nil
3.1.0 :159 > array_100k = Array.new(100000,0)
=>
[0,
...
3.1.0 :160 > puts Benchmark.measure { 1_000_000.times { |n|
array_100k[rand*100_000] } }
  0.213250 0.000000 0.213250 ( 0.213260)
=> nil
3.1.0 :161 > puts Benchmark.measure { 1_000_000.times { |n|
array_100k[rand*100_000] } }
  0.204273 0.000000 0.204273 ( 0.204281)
=> nil
3.1.0 :162 > puts Benchmark.measure { 1_000_000.times { |n|
array_100k[rand*100_000] } }
  0.224937 0.000000 0.224937 ( 0.225697)
=> nil

Source says it's an array:

<http://goog_628926836>

ruby/rarray.h at acd1f45a5c0a35bcafef8c31b1429126a5efa3ea · ruby/ruby · GitHub

/**
* Pointer to the C array that holds the elements of the array. In
* the old days each array had dedicated memory regions. That is
* no longer true today, but there still are arrays of such
* properties. This field could be used to point such things.
*/
const VALUE *ptr;

It may be different for other Ruby implementations.

The sizing of a dynamic array is an exercise in trade-offs. If you have
large amounts of in-memory data and specific performance requirements,
benchmark high perf libraries for your situation.

-gf-

On Thu, Jan 13, 2022 at 5:22 AM Yamadaえりな <yamoerina@gmail.com> wrote:

A developer from Scala group says, "never use Array unless you know what
you are doing exactly".
List is suitable for 99% of jobs IMO. But sometimes we do need a high
performance computing library.

ありがとう
えりな

On Thu, Jan 13, 2022 at 6:19 PM Yamadaえりな <yamoerina@gmail.com> wrote:

Random access to Array is o(1), while to List is o(n).
Please see this article:
Lists Part III: Lists vs Arrays. Data Structures in Ruby | by D. L. Jerome | Medium

Python by default has no Array too, but Array exists in its Numpy
library.

ありがとう
えりな

On Thu, Jan 13, 2022 at 6:04 PM Edward <edward.caulfield@gmx.ch> wrote:

Just out of curiosity, what benefits are you looking for that aren't
already in Ruby's implementation of an Array?

Edward

On 13.01.22 09:57, Die Optimisten wrote:
> Hi
>
> No, there is just Array, which is a list.
>
> Maybe there are some gems providing real arrays.
>
> Opti
>
>
>
> Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org
?subject=unsubscribe>
> <ruby-talk list: member options login page>

--
Freundliche Grüsse

Edward Caulfield

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org
?subject=unsubscribe>
<ruby-talk list: member options login page>

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<ruby-talk list: member options login page>

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<ruby-talk list: member options login page>