Big O notation for Ruby methods?

后端 未结 3 826
陌清茗
陌清茗 2021-01-19 19:53

How can I find the complexity of a Ruby method?

For example length? If I look at the source code, I see this:

               static VALUE
rb_ary_len         


        
3条回答
  •  误落风尘
    2021-01-19 20:27

    It is just O(1) for the length method. The length of an array is stored in a variable and can be returned without further calculations.

    How to find out? By reading the source code and analysing the implementation and algorithms.

提交回复
热议问题