MOO-cows Mailing List Archive

[Prev][Next][Index][Thread]

Re: List operations: (reverse range) (SERVER mods)



[Lots cut..]

>I many times need to know what index i'm at. so I code:
>
>counter=0;
>for i in  ({list})
>counter=counter+1;
>
>I can't use (counter= i in {list})  since the same element may appear
>twice in the list.
>
>it would be nice to have :
>
>for i in ({list}) count i_counter

Yes, this would be incredibly usefull.

On a slightly different subject, does anyone have any information on 
relative speeds of list operations? For example: How efficient (in CPU 
cycles, not MOO cycles), is 'foundString = string in (list_of_strings)' 
or 'objectNumber = object in (list_of_objects)'? Would it be faster, in 
the first example, to convert the list to a long string (assuming each 
string was the same length) and then use index()?

Also, is faster to have a list as a property or to have it as a local variable?

I notice, that if I have a list as a local variable, the MOO produces:

  0: 124           NUM 1
  1: 016         * MAKE_SINGLETON_LIST
  2: 125           NUM 2
  3: 102           LIST_ADD_TAIL
  4: 126           NUM 3
  5: 102           LIST_ADD_TAIL
  6: 127           NUM 4
  7: 102           LIST_ADD_TAIL
  8: 050         * PUT x
  9: 111           POP
 10: 110           DONE

Whereas, if I define the list as a property, the MOO produces:

  0: 073           PUSH this
  1: 100 000       PUSH_LITERAL "test"
  3: 009         * GET_PROP
  4: 050         * PUT x
  5: 111           POP
  6: 110           DONE

Which is less opcodes, but is it actually faster? Is it only faster for 
certain length lists?

--C.S.



Home | Subject Index | Thread Index