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

new example: ctypes #441

Merged
merged 5 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions examples/ctypes-factorial/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# pixi environments
.pixi

# shared objects
**/*.dll
**/*.so
25 changes: 25 additions & 0 deletions examples/ctypes-factorial/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Ctypes example: large factorials

This examples calculates approximate factorials of large numbers using pure Python or Python with ctypes.


## Features demonstrated:
- packaging C and Python libraries together
- compiling with gcc through Pixi tasks
- conditional Pixi task execution (`depends_on`)
- defining tasks with arguments


## Output

C implementation used in Python via ctypes was about 5x faster than pure python on the author's machine. How fast was your setup?

```
$ pixi run factorial 12345678 python
2023-11-06@18:49:19.296216|INFO|__main__.<module>:50|calculating approximate factorial of 12345678 using pure Python...
2023-11-06@18:49:23.992089|INFO|__main__.<module>:61|12345678! ≈ 1.457260e82187904

$ pixi run factorial 12345678 ctypes
2023-11-06@18:49:29.404679|INFO|__main__.<module>:53|calculating factorial of 12345678 using ctypes...
2023-11-06@18:49:29.947188|INFO|__main__.<module>:61|12345678! ≈ 1.457260e82187904
```
Loading