pbrady / fastcache

C implementation of Python 3 lru_cache
MIT License
154 stars 19 forks source link

Speed comparison on Python35 and latter #55

Closed 892768447 closed 4 years ago

892768447 commented 4 years ago
Python 3.5.4 (v3.5.4:3f56838, Aug  8 2017, 02:07:06) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from fastcache import benchmark
>>> benchmark.run()
Test Suite 1 :

Primarily tests cost of function call, hashing and cache hits.
Benchmark script based on
    http://bugs.python.org/file28400/lru_cache_bench.py

function call                 speed up
untyped(i)                        0.53, typed(i)                          0.63
untyped("spam", i)                0.51, typed("spam", i)                  0.67
untyped("spam", "spam", i)        0.57, typed("spam", "spam", i)          0.63
untyped(a=i)                      0.87, typed(a=i)                        0.89
untyped(a="spam", b=i)            1.01, typed(a="spam", b=i)              1.04
untyped(a="spam", b="spam", c=i)  1.17, typed(a="spam", b="spam", c=i)    1.08

             min   mean    max
untyped    0.508  0.776  1.171
typed      0.632  0.824  1.080

Test Suite 2 :

Tests millions of misses and millions of hits to quantify
cache behavior when cache is full.

function call                 speed up
untyped(i, j, a="spammy")         0.93, typed(i, j, a="spammy")           0.92
>>>
892768447 commented 4 years ago

I think it can be directly used functools.lru_cache in python35 and latter

pbrady commented 4 years ago

I added a performance warning on the readme for python >= 3.5