Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not fast? #2

Closed
sonots opened this issue Aug 9, 2017 · 4 comments
Closed

Not fast? #2

sonots opened this issue Aug 9, 2017 · 4 comments

Comments

@sonots
Copy link
Contributor

sonots commented Aug 9, 2017

I wrote benchmark scripts as follows to compare:

lock_bench.py

import time
import threading

lock = threading.RLock()

start_time = time.time()
for i in range(100000):
    lock.acquire()
    lock.release()
    # with lock:
    #     pass
elapsed_time = time.time() - start_time
print(elapsed_time)

fastrlock_bench.py

import time
from fastrlock import rlock

lock = rlock.FastRLock()

start_time = time.time()
for i in range(100000):
    lock.acquire()
    lock.release()
    # with lock:
    #     pass
elapsed_time = time.time() - start_time
print(elapsed_time)

I obtained following results which show fastrlock is not fast.

$ python ~/lock_bench.py
0.03992772102355957
$ python ~/fastrlock_bench.py
0.04404258728027344

My python and cython version is as follows:

$ python --version
Python 3.6.1
$ cython --version
Cython version 0.25.2

Could you tell me if I am doing something wrong?

@scoder
Copy link
Owner

scoder commented Aug 9, 2017

Interesting. I hadn't run benchmarks in a while. Looks like threading.RLock is faster starting with Py3.4. FastRLock is essentially unchanged since 2010. Probably no longer worth using these days then (well, except in Python 2 where the advantage is huge, or maybe also when called directly from Cython code).

@scoder scoder closed this as completed Aug 9, 2017
@sonots
Copy link
Contributor Author

sonots commented Aug 10, 2017

Thank you!

@sonots
Copy link
Contributor Author

sonots commented Aug 10, 2017

Additional comments:

In the case of cython with FastRLock C API, fastrlock was pretty faster than threading.RLock even in Py3.6. Thanks!

@scoder
Copy link
Owner

scoder commented Aug 10, 2017

Thanks for reporting back!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants