dcramer / mangodb

A database that operates at CLOUD SCALE
902 stars 70 forks source link

Don't keep re-reading environ variables per request #36

Closed mattrobenolt closed 11 years ago

mattrobenolt commented 11 years ago

webscale

enomado commented 11 years ago

Guys, i was concerned about appropriateness of this optimization, since os.environ may change in runtime and no one will be there to detect that. I wrote test just to make sure these sacrifices are really worth performance we gain for them, and numbers speak for themselves - it's worth every bit optimized.

In [15]: timeit.timeit('b = os.environ.get("MANGO")',setup='import os', number=10000000) Out[15]: 9.007932901382446

In [16]: timeit.timeit('b = s.get("MANGO")',setup='import os; s = os.environ', number=10000000) Out[16]: 8.13143801689148

In [17]: timeit.timeit('b = s("MANGO")',setup='import os; s = os.environ.get', number=10000000) Out[17]: 6.740509986877441

In [18]: timeit.timeit('b = s()',setup='import os; s = lambda :os.environ.get("MANGO")', number=10000000) Out[18]: 10.55083703994751

In [20]: timeit.timeit('b = s',setup='import os; s=1', number=10000000) Out[20]: 0.32480502128601074