Skip to main content

Rust library for sum of squares calculation exposed to Python via PyO3

Project description

pyo3-sum

Высокопроизводительная Rust-библиотека для вычисления суммы квадратов чисел, доступная из Python через PyO3.

Установка

pip install pyo3-sum

Или соберите локально:

# Установка зависимостей
pip install maturin

# Сборка и установка
maturin develop --release

Использование

from pyo3_sum import sum_of_squares

# Вычисление суммы квадратов от 1 до n
result = sum_of_squares(10)
print(result)  # 385 (1² + 2² + ... + 10²)

# Большие числа
result = sum_of_squares(1_000_000)
print(result)  # 333333833333500000

Производительность

Метод Время (N=1_000_000) Ускорение
pyo3-sum ~0.02 сек 2x быстрее Python
Чистый Python ~0.04 сек 1.0x (базовый)

API

sum_of_squares(n: int) -> int

Вычисляет сумму квадратов чисел от 1 до n.

Аргументы:

  • n (int): Верхняя граница диапазона (включительно). Должно быть неотрицательным целым числом.

Возвращает:

  • int: Сумма квадратов чисел от 1 до n.

Пример:

>>> sum_of_squares(0)
0
>>> sum_of_squares(1)
1
>>> sum_of_squares(5)
55  # 1 + 4 + 9 + 16 + 25
>>> sum_of_squares(10)
385

Сборка

Требования

Локальная сборка

# Debug сборка (быстрее, для разработки)
maturin develop

# Release сборка (медленнее, оптимизирована)
maturin develop --release

# Сборка wheel
maturin build --release

Кроссплатформенная сборка

Используйте GitHub Actions для сборки wheel'ов для всех платформ:

# Триггер для сборки (требуется GH CLI)
gh workflow run build_wheels.yml

Тестирование

# Rust тесты
cargo test

# Python тесты
python -c "import pyo3_sum; assert pyo3_sum.sum_of_squares(10) == 385"

Лицензия

MIT License - см. файл LICENSE.

Вклад в проект

  1. Fork репозиторий
  2. Создайте feature branch (git checkout -b feature/amazing-feature)
  3. Commit изменения (git commit -m 'Add amazing feature')
  4. Push в branch (git push origin feature/amazing-feature)
  5. Откройте Pull Request

Бенчмарк

Для сравнения производительности с чистым Python и Go:

cd benchmark
python benchmark.py -n 1000000 -i 5

См. benchmark/README.md для подробностей.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pyo3_sum-0.1.3-cp312-cp312-win_amd64.whl (98.2 kB view details)

Uploaded CPython 3.12Windows x86-64

pyo3_sum-0.1.3-cp312-cp312-manylinux_2_34_x86_64.whl (233.3 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

File details

Details for the file pyo3_sum-0.1.3-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: pyo3_sum-0.1.3-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 98.2 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyo3_sum-0.1.3-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 2bda900a9afddbf070f35c207aa91a07c21eeacba9d079ac7cbcb6b509ac3b23
MD5 71ee013dc33a1347ec2e890ae2a229d2
BLAKE2b-256 47025a584f9bc971b0922e13480c168d6b59455847ae8c88dbdcc478184ea949

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyo3_sum-0.1.3-cp312-cp312-win_amd64.whl:

Publisher: publish_pypi.yml on MarkFrizen/LR9

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyo3_sum-0.1.3-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for pyo3_sum-0.1.3-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 9015d2ca57d19fa60dd58f88c9456d294d9dcb7218cff9a1afc03619cfb18a71
MD5 55b0b792300aca24d0e7e95a7587c66d
BLAKE2b-256 c47b64b1b90879e29989ed43ca39ebebfcfd0d0d9ab926ecfe3871f32afd605c

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyo3_sum-0.1.3-cp312-cp312-manylinux_2_34_x86_64.whl:

Publisher: publish_pypi.yml on MarkFrizen/LR9

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page