Big O notation for Ruby methods?

后端 未结 3 812
陌清茗
陌清茗 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:12

    You cannot get the relevant information from that. You have to look into the source of RARRAY_LEN and LONG2NUM.

    A simple way to estimate the complexity of a method is to run benchmarks with arguments that differ along the dimension you are interested in, and plot that on a graph.

提交回复
热议问题