-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
documented multithreaded, and make test runnable by pytest
- Loading branch information
Showing
2 changed files
with
28 additions
and
12 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -1,24 +1,21 @@ | ||
from concurrent.futures import ThreadPoolExecutor, wait | ||
|
||
import numpy as np | ||
|
||
import qoi | ||
|
||
RGB = np.random.randint(low=0, high=255, size=(224, 244, 3)).astype(np.uint8) | ||
RGBA = np.random.randint(low=0, high=255, size=(224, 244, 4)).astype(np.uint8) | ||
|
||
|
||
def worker(): | ||
bites = bytearray(qoi.encode(RGB)) | ||
img_decoded = qoi.decode(bites) | ||
# print("done") | ||
decoded = qoi.decode(bites) | ||
assert np.array_equal(RGB, decoded) | ||
|
||
|
||
def main(): | ||
def test_multithreaded(): | ||
""" | ||
Note that this doesn't really test the performance, but it at least validates that it runs multithreaded. | ||
""" | ||
with ThreadPoolExecutor(8) as pool: | ||
futures = [pool.submit(worker) for _ in range(10000)] | ||
futures = [pool.submit(worker) for _ in range(100)] | ||
wait(futures) | ||
print("Did you see that in top? Congratulations you have bypass the gil") | ||
|
||
if __name__ == "__main__": | ||
main() |