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.0-cp312-cp312-win_amd64.whl (98.2 kB view details)

Uploaded CPython 3.12Windows x86-64

pyo3_sum-0.1.0-cp312-cp312-manylinux_2_34_x86_64.whl (233.2 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

File details

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

File metadata

  • Download URL: pyo3_sum-0.1.0-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.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 4defac4b95d3c0db94fb69c64eda6f4ee98f734d3fa0fe95876b4aade89440fc
MD5 0dcdf4274554495f56c2a151a35b48e7
BLAKE2b-256 09105b10bb993c2ba368445691aeaeb4438db9528dc8251475275c7bb31aa801

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyo3_sum-0.1.0-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.0-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for pyo3_sum-0.1.0-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 f98dca5f88015eb1893facf292171671e1285ae7ec72fbab7343912093eced03
MD5 933cd1dc59ec233274fe1ff0e32feb0f
BLAKE2b-256 9c40280a8656d5deed6bb918a98ac999368e53224c15002adda4054c3b29cb06

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyo3_sum-0.1.0-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