Skip to main content

Fast float repr

Project description

frepr

https://travis-ci.org/wemoloh/frepr.svg?branch=master

Fast float repr() for CPython using https://github.com/google/double-conversion. Approximately 8X faster than the built-in function.

Quick Start

>>> import frepr
>>> frepr.frepr(-1.8397892359791307e+134)
'-1.8397892359791307e+134'
>>> from timeit import timeit
>>> timeit('repr(-1.8397892359791307e+134)')
2.7296602272476758
>>> frepr.install()
>>> timeit('repr(-1.8397892359791307e+134)')
0.35723431229251545
>>> frepr.uninstall()

API

frepr.frepr(value)

Returns shortest string representation of a floating point value. The argument doesn’t have to be a float, as long as it is coercible to one (i.e. it has a __float__() method).

frepr.install()

Monkey-patches the Python runtime. Subsequent calls to repr() on floats will use the faster algorithm. This is safe to call multiple times.

frepr.uninstall()

Reverses the monkey-patching done by install(). Subsequent calls to repr() will use the original built-in algorithm. This is safe to call multiple times, even if install() was not called first.

Features

  • On average, approximately 8X faster than the standard function. (This result obtained on Python 3.6.0 64-bit/Windows 7/Intel Core i3 @ 2.93GHz. Test your own system with tests/perf.py).

  • Speeds up the standard json package (and any other library that relies on repr()).

  • Output is guaranteed to contain the shortest string of decimal digits necessary to uniquely identify the original IEEE 754 floating-point value.

  • Guaranteed to satisfy value == ast.literal_eval(frepr(value)).

  • Tested on CPython 2.6 through 3.6; probably works on other versions too.

Limitations

  • Currently, there is no support for alternative Python implementations (e.g. PyPy).

  • Output can be slightly different from the native function, due to floating-point rounding (but see accuracy guarantees above).

  • Has no effect on other built-in methods of converting floats to strings (e.g. str(), str.format(), "%f", "%g").

See Also

Project details


Download files

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

Source Distribution

frepr-0.1.1.tar.gz (58.2 kB view details)

Uploaded Source

Built Distributions

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

frepr-0.1.1-cp36-cp36m-win_amd64.whl (25.1 kB view details)

Uploaded CPython 3.6mWindows x86-64

frepr-0.1.1-cp36-cp36m-win32.whl (20.8 kB view details)

Uploaded CPython 3.6mWindows x86

frepr-0.1.1-cp35-cp35m-win_amd64.whl (25.1 kB view details)

Uploaded CPython 3.5mWindows x86-64

frepr-0.1.1-cp35-cp35m-win32.whl (20.8 kB view details)

Uploaded CPython 3.5mWindows x86

frepr-0.1.1-cp34-cp34m-win_amd64.whl (31.5 kB view details)

Uploaded CPython 3.4mWindows x86-64

frepr-0.1.1-cp34-cp34m-win32.whl (26.7 kB view details)

Uploaded CPython 3.4mWindows x86

frepr-0.1.1-cp27-cp27m-win_amd64.whl (31.1 kB view details)

Uploaded CPython 2.7mWindows x86-64

frepr-0.1.1-cp27-cp27m-win32.whl (26.7 kB view details)

Uploaded CPython 2.7mWindows x86

File details

Details for the file frepr-0.1.1.tar.gz.

File metadata

  • Download URL: frepr-0.1.1.tar.gz
  • Upload date:
  • Size: 58.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for frepr-0.1.1.tar.gz
Algorithm Hash digest
SHA256 c87f9a996b7767a887a4b1590b1ab6cbe33825e3793b505cc07f172152b294b4
MD5 c58c816901905f0627c3ac56cc0ac634
BLAKE2b-256 716bd9f3514a2a10b628b485f4b3a99119e70a7c99c748f03e9443e87e3cb39d

See more details on using hashes here.

File details

Details for the file frepr-0.1.1-cp36-cp36m-win_amd64.whl.

File metadata

File hashes

Hashes for frepr-0.1.1-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 c7735e6a22fff426aaa28c274986de0eddfc7e3599aca42af9fd6095f50ad77d
MD5 94c7d1a82d3f1d7a660b4e0b7ba2471a
BLAKE2b-256 c3d3e3b048ae321334ab83046f198e7ec7bcea04c3652562d2929a4310e2bd95

See more details on using hashes here.

File details

Details for the file frepr-0.1.1-cp36-cp36m-win32.whl.

File metadata

File hashes

Hashes for frepr-0.1.1-cp36-cp36m-win32.whl
Algorithm Hash digest
SHA256 466b4284b1e952c3e81c17208f709f2fbc1723b9a5deb9a9acbfeb90f4e86c35
MD5 5c93b6cd5fbe3a37924b466e1e91dae0
BLAKE2b-256 43faef937630bdb23aa295d4fc688bf15fccc51a47b19b29b54dbe0bdeb35e44

See more details on using hashes here.

File details

Details for the file frepr-0.1.1-cp35-cp35m-win_amd64.whl.

File metadata

File hashes

Hashes for frepr-0.1.1-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 69a027a4605a8a5a4123cc91ad6f4d858d797116d20f604553df641cf53a469f
MD5 cb08d66faf9001a291a039afdc0dae48
BLAKE2b-256 6e3aabd2a0e15a986e307d0d9b65ec167249792e47e5bf9f90522d33d63e7f30

See more details on using hashes here.

File details

Details for the file frepr-0.1.1-cp35-cp35m-win32.whl.

File metadata

File hashes

Hashes for frepr-0.1.1-cp35-cp35m-win32.whl
Algorithm Hash digest
SHA256 c84a066df6bee5df4f920c3d7817cb1bf94fdf262b6b828325fc7f61fd9c3872
MD5 3ece0e7e1ca4c8be9eb833da1cce5998
BLAKE2b-256 3f4f58a281854b6adde87829610947e49190271e8617d3d2120847636a7f1804

See more details on using hashes here.

File details

Details for the file frepr-0.1.1-cp34-cp34m-win_amd64.whl.

File metadata

File hashes

Hashes for frepr-0.1.1-cp34-cp34m-win_amd64.whl
Algorithm Hash digest
SHA256 a0bc461ceb128f072f59b2363a8f3df263664f40c7752029babdb2dd4dc1963f
MD5 70dd121dbec4aa5d1c819fa2f76285ae
BLAKE2b-256 682799100364d1f99ccd9d04e6147ec9b19ebb58ba976fa49d8f3061549b6554

See more details on using hashes here.

File details

Details for the file frepr-0.1.1-cp34-cp34m-win32.whl.

File metadata

File hashes

Hashes for frepr-0.1.1-cp34-cp34m-win32.whl
Algorithm Hash digest
SHA256 e4174c4ad88416e76a9ea69ab1b3b3306488c40e1ab78f07a6213de8c5355ed1
MD5 f75bb717774f74d77a67bdfed2ff27d3
BLAKE2b-256 db04ee015654c91028e5d8ca064806438b3bd0afbf3805a58b87d9f8630e91c7

See more details on using hashes here.

File details

Details for the file frepr-0.1.1-cp27-cp27m-win_amd64.whl.

File metadata

File hashes

Hashes for frepr-0.1.1-cp27-cp27m-win_amd64.whl
Algorithm Hash digest
SHA256 b6c13f9eb8f5a739020832003e8e9547e38518a4df1f3c469cb73757e2487c8c
MD5 635cc01911259671506a4b3c8f34e421
BLAKE2b-256 97db1ca8018a6ca5f765c218e4ce98d0259ddf8f55adeb75fcd262f1956f2ae0

See more details on using hashes here.

File details

Details for the file frepr-0.1.1-cp27-cp27m-win32.whl.

File metadata

File hashes

Hashes for frepr-0.1.1-cp27-cp27m-win32.whl
Algorithm Hash digest
SHA256 c20534b26f358ef18e1db7c9c2ab50729a7d0271509cc222bf101f234266c9f4
MD5 491c1e199c36d3734ab6997b8bf56530
BLAKE2b-256 9d989fe7b102d000448fa86761abaf5a816e308c6f9589ea786ff428dec7100d

See more details on using hashes here.

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