GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - scoder/quicktions: Fast fractions reimplementation in Cython

BranchesTags
Open more actions menu

Latest commit

 

History

489 Commits
489 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
benchmark
benchmark
 
 
src
src
 
 
.coveragerc
.coveragerc
 
 
.gitignore
.gitignore
 
 
.travis.yml
.travis.yml
 
 
CHANGES.rst
CHANGES.rst
 
 
LICENSE
LICENSE
 
 
MANIFEST.in
MANIFEST.in
 
 
Makefile
Makefile
 
 
README.rst
README.rst
 
 
appveyor.yml
appveyor.yml
 
 
appveyor_env.cmd
appveyor_env.cmd
 
 
dedup_wheels.py
dedup_wheels.py
 
 
gen_todecimal.py
gen_todecimal.py
 
 
pyproject.toml
pyproject.toml
 
 
requirements.txt
requirements.txt
 
 
setup.py
setup.py
 
 
tox.ini
tox.ini
 
 

Repository files navigation

quicktions

Python's Fraction data type is an excellent way to do exact calculations with unlimited rational numbers and largely beats Decimal in terms of simplicity, accuracy and safety. Clearly not in terms of speed, though, given the cdecimal accelerator in Python 3.3+.

quicktions is an adaptation of the original fractions module (as included in CPython 3.13) that is compiled and optimised with Cython into a fast, native extension module.

Compared to the standard library fractions module of CPython 3.12, computations in quicktions are about 2-4x faster.

Instantiation of a Fraction in quicktions is also

  • 5-15x faster from a floating point string value (e.g. Fraction("123.456789"))
  • 3-5x faster from a floating point value (e.g. Fraction(123.456789))
  • 2-5x faster from an integer numerator-denominator pair (e.g. Fraction(123, 456))

We provide a set of micro-benchmarks here:

https://github.com/scoder/quicktions/tree/master/benchmark

As of quicktions 1.19, the different number types and implementations compare as follows in CPython 3.12 (measured on Ubuntu Linux):

Average times for all 'create' benchmarks:
float               :    19.69 us (1.0x)
Fraction            :    58.63 us (3.0x)
Decimal             :    84.32 us (4.3x)
PyFraction          :   208.20 us (10.6x)

Average times for all 'compute' benchmarks:
float               :     1.79 us (1.0x)
Decimal             :    10.11 us (5.7x)
Fraction            :    39.24 us (22.0x)
PyFraction          :    96.23 us (53.9x)

While not as fast as the C implemented decimal module in Python 3, quicktions is about 15x faster than the Python implemented decimal module in Python 2.7.

For documentation, see the Python standard library's fractions module:

https://docs.python.org/3/library/fractions.html

About

Fast fractions reimplementation in Cython

pypi.python.org/pypi/quicktions

Resources

Readme
License
Activity

Stars

39 stars

Watchers

1 watching

Forks

3 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.