3 ms·
I like the idea, but there seems to be a bit of a performance hit. >>> from timeit import Timer >>> mokatimer = Timer("l = List(range(1000)).extend(range(1000
by gaelenh 15y ago
I like the idea, but there seems to be a bit of a performance hit.
>>>
from timeit import Timer
>>>
mokatimer = Timer("l = List(range(1000)).extend(range(1000, 2000)).keep(lambda x: (x % 3) == 1)", setup="from moka import List")
>>>
regtimer = Timer("l = range(1000); l.extend(range(1000, 2000)); l = [n for n in l if (n % 3) == 1]")
>>>
mokatimer.timeit(10000)
16.502125024795532
>>>
regtimer.timeit(10000)
2.5419421195983887
I tried pre-generating the range to see if that was throwing it off the timer:
>>>
regtimer = Timer("l = []; l.extend(range1000); l = [n for n in l if (n % 3) == 1]", setup="range1000 = range(1000)")
>>>
mokatimer = Timer("l = List().extend(range1000).keep(lambda x: (x % 3) == 1)", setup="from moka import List; range1000=range(1000)")
>>>
regtimer.timeit(10000)
1.0892798900604248
>>>
mokatimer.timeit(10000)
7.714169979095459
I didn't look at the source, but it looks like moka needs to be optimized to use list comprehension for .keep. Other methods could probably use comprehension (or generators) too.
- phzbOx 15y agoThanks for the feedback. Yes, I totally agree about the performance hit. I'm still thinking about the interface and what methods Moka should provide. After that, I'll make a pass to optimize constructs as much as possible.