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 Distribution

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

pyo3_sum-0.1.1-cp312-cp312-manylinux_2_34_x86_64.whl (233.4 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

File details

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

File metadata

File hashes

Hashes for pyo3_sum-0.1.1-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 bd7e32adbda55ecbd4487e8fa383152496aed57f3580093bf429b19de821e7cc
MD5 b75a813c34334e5e262ae2b5d7d6b536
BLAKE2b-256 bd716ae68e6b61d292bf195a54a625483077a312294485823ac7181a19bcc3ba

See more details on using hashes here.

Provenance

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