2006-09-13

What's the difference between obj.n == 1 and dict['n'] == 1?

A lot of time.

Running

>>> if o.n == 1 and o.p == 1:
... pass
takes about 1,4 times longer than
>>> if d['n'] == 1 and d['p'] == 1:
... pass
Here are the results of iterating 10 000 000 times.
05.428000 seconds (obj)
03.896000 seconds (dict)

the actual runtime varies a little but the relation between the resulting values stays at about 1,4. Of course this metric is far too simple to base a decision about how to implement an Alpha Network on. As soon as I have a *complete* implementation of a Working Memory and an Alpha Network using a Linked List I'll perform a more realistic test.

[2006-09-16] Update:
In case you thought I forgot about:
>>>if o1.__dict__['n'] == 1 and o1.__dict__['p'] == 1:
... pass
I didn't include them because the run time is worse than using dot notation. Here are the complete results of iterating 10 000 000 times.
0:00:05.598000 (obj.attr)
0:00:06.319000 (obj.__dict__[attr])
0:00:03.875000 (dict)

1 kommentar:

woolfel sa...

Perhaps this idea will assist in your efforts http://woolfel.blogspot.com/2006/09/duck-typing-and-rete.html

peter