-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
409a32e
commit 2952054
Showing
4 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import asyncio | ||
from string import ascii_lowercase | ||
from timeit import timeit | ||
|
||
from aiocache.backends.redis import RedisCache | ||
from aiocache.backends.memory import SimpleMemoryCache | ||
from shared_memory_dict.caches.aiocache import SharedMemoryCache | ||
|
||
loop = asyncio.get_event_loop() | ||
|
||
cache_smc_aiocache = SharedMemoryCache(size=64) | ||
cache_aiocache_redis = RedisCache(loop=loop) | ||
cache_aiocache_memory = SimpleMemoryCache() | ||
|
||
|
||
async def agressive(cache): | ||
for c in ascii_lowercase: | ||
for i in range(5): | ||
await cache.set(f'{c}{i}', '1') | ||
for i in range(10, 0, -1): | ||
await cache.get(f'{c}{i}') | ||
|
||
|
||
async def fun(cache): | ||
await cache.set('fun', 'uhull') | ||
for _ in range(3): | ||
await cache.get('fun') | ||
|
||
|
||
def collect(cache_var_name): | ||
time_of_agressive = timeit( | ||
stmt=f'loop.run_until_complete(agressive({cache_var_name}))', | ||
number=100, | ||
globals=globals() | ||
) | ||
time_of_fun = timeit( | ||
stmt=f'loop.run_until_complete(fun({cache_var_name}))', | ||
number=100, | ||
globals=globals() | ||
) | ||
|
||
return { | ||
'agressive': time_of_agressive, | ||
'fun': time_of_fun | ||
} | ||
|
||
|
||
if __name__ == '__main__': | ||
caches = { | ||
k: collect(k) | ||
for k in globals().keys() | ||
if k.startswith('cache_') | ||
} | ||
|
||
print('Bench Against Async Solutions') | ||
for k, v in caches.items(): | ||
print(f'Cache Type : {k}:') | ||
print(f'agressive : {v["agressive"]}') | ||
print(f'fun : {v["fun"]}') | ||
print('') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
SECRET_KEY = 'bla' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
from string import ascii_lowercase | ||
from timeit import timeit | ||
|
||
from django.core.cache.backends.locmem import LocMemCache | ||
from django_redis.cache import RedisCache | ||
from shared_memory_dict.caches.django import SharedMemoryCache | ||
|
||
cache_smc_django = SharedMemoryCache( | ||
'django', params={'OPTIONS': {'MEMORY_BLOCK_SIZE': 64}} | ||
) | ||
cache_django_redis = RedisCache(server='redis://127.0.0.1:6379/1', params={}) | ||
cache_django_locmem = LocMemCache('locmem', params={}) | ||
|
||
|
||
def agressive(cache): | ||
for c in ascii_lowercase: | ||
for i in range(5): | ||
cache.set(f'{c}{i}', '1') | ||
for i in range(10, 0, -1): | ||
cache.get(f'{c}{i}') | ||
|
||
|
||
def fun(cache): | ||
cache.set('fun', 'uhull') | ||
for _ in range(3): | ||
cache.get('fun') | ||
|
||
|
||
def collect(cache_var_name): | ||
time_of_agressive = timeit( | ||
stmt=f'agressive({cache_var_name})', number=100, globals=globals() | ||
) | ||
time_of_fun = timeit( | ||
stmt=f'fun({cache_var_name})', number=100, globals=globals() | ||
) | ||
|
||
return { | ||
'agressive': time_of_agressive, | ||
'fun': time_of_fun | ||
} | ||
|
||
|
||
if __name__ == '__main__': | ||
caches = { | ||
k: collect(k) | ||
for k in globals().keys() | ||
if k.startswith('cache_') | ||
} | ||
|
||
print('Bench Against Sync Solutions') | ||
for k, v in caches.items(): | ||
print(f'Cache Type : {k}:') | ||
print(f'agressive : {v["agressive"]}') | ||
print(f'fun : {v["fun"]}') | ||
print('') |