From 4659cc53ff0d4600cf36fefb620968fa6ab6097d Mon Sep 17 00:00:00 2001 From: Dorian Pula Date: Wed, 30 Oct 2019 10:37:01 -0400 Subject: [PATCH] Add in benchmarks. --- Pipfile | 5 ++--- Pipfile.lock | 57 ++++++++++++++++++++++++++++++++-------------------- README.md | 2 +- test.py | 15 ++++++++++++++ 4 files changed, 53 insertions(+), 26 deletions(-) diff --git a/Pipfile b/Pipfile index 2c0172f..af2d34b 100644 --- a/Pipfile +++ b/Pipfile @@ -3,12 +3,11 @@ name = "pypi" url = "https://pypi.org/simple" verify_ssl = true -[dev-packages] -maturin = "*" - [packages] pyo3-pack = "*" pytest = "*" +pytest-benchmark = "*" +maturin = "*" [requires] python_version = "3.6" diff --git a/Pipfile.lock b/Pipfile.lock index feb9df3..e990cbf 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "f446b2fd462f856414a21e7626c27a9736f94dca7ec455bfc5c575699f366703" + "sha256": "6abbd7128fe33662a80c04ff5d016c068652998013bb51d519098f30f7b5f182" }, "pipfile-spec": 6, "requires": { @@ -38,6 +38,18 @@ "markers": "python_version < '3.8'", "version": "==0.23" }, + "maturin": { + "hashes": [ + "sha256:0e58532b845aad5d1a1df9dd6ef56456d63b737e4a3a30e8572447fbc23d151f", + "sha256:4e2f73f97d2f030da42a2758e56e95ce2491afd9a080e70b78b088128145af87", + "sha256:90efda63af6c565a986d1e050673e033cbefc3c9b2996fa2fdf9e6d94d5bd179", + "sha256:9eecde82ee37772764d6237b7784912241d0b93292f72ff29a921f33842691ca", + "sha256:a435b280afcba7a1ca7203a60b198d8f93d874db0ffed13ee537c5066160b429", + "sha256:ab75ad31257d2238673bde7d402c2e7608e37a8042350ca7fd51f70382a1a638" + ], + "index": "pypi", + "version": "==0.7.6" + }, "more-itertools": { "hashes": [ "sha256:409cd48d4db7052af495b09dec721011634af3753ae1ef92d2b32f73a745f832", @@ -66,6 +78,12 @@ ], "version": "==1.8.0" }, + "py-cpuinfo": { + "hashes": [ + "sha256:2cf6426f776625b21d1db8397d3297ef7acfa59018f02a8779123f3190f18500" + ], + "version": "==5.0.0" + }, "pyo3-pack": { "hashes": [ "sha256:3b9b34ba43ad009c3b4ad3f508d0d364891f47242f47a604b4e5ea68dfcab32d", @@ -92,6 +110,14 @@ "index": "pypi", "version": "==5.2.2" }, + "pytest-benchmark": { + "hashes": [ + "sha256:4512c6805318d07926efcb3b39f7b98a10d035305a93edfd5329c86cbf9cfbf7", + "sha256:ab851115ce022639173b9497d4a4183a1d8fe9cdcf8fab9d8a57607008aedd3d" + ], + "index": "pypi", + "version": "==3.2.2" + }, "six": { "hashes": [ "sha256:3350809f0555b11f552448330d0b52d5f24c91a322ea4a15ef22629740f3761c", @@ -99,6 +125,13 @@ ], "version": "==1.12.0" }, + "toml": { + "hashes": [ + "sha256:229f81c57791a41d65e399fc06bf0848bab550a9dfd5ed66df18ce5f05e73d5c", + "sha256:235682dd292d5899d361a811df37e04a8828a5b1da3115886b73cf81ebc9100e" + ], + "version": "==0.10.0" + }, "wcwidth": { "hashes": [ "sha256:3df37372226d6e63e1b1e1eda15c594bca98a22d33a23832a90998faa96bc65e", @@ -114,25 +147,5 @@ "version": "==0.6.0" } }, - "develop": { - "maturin": { - "hashes": [ - "sha256:0e58532b845aad5d1a1df9dd6ef56456d63b737e4a3a30e8572447fbc23d151f", - "sha256:4e2f73f97d2f030da42a2758e56e95ce2491afd9a080e70b78b088128145af87", - "sha256:90efda63af6c565a986d1e050673e033cbefc3c9b2996fa2fdf9e6d94d5bd179", - "sha256:9eecde82ee37772764d6237b7784912241d0b93292f72ff29a921f33842691ca", - "sha256:a435b280afcba7a1ca7203a60b198d8f93d874db0ffed13ee537c5066160b429", - "sha256:ab75ad31257d2238673bde7d402c2e7608e37a8042350ca7fd51f70382a1a638" - ], - "index": "pypi", - "version": "==0.7.6" - }, - "toml": { - "hashes": [ - "sha256:229f81c57791a41d65e399fc06bf0848bab550a9dfd5ed66df18ce5f05e73d5c", - "sha256:235682dd292d5899d361a811df37e04a8828a5b1da3115886b73cf81ebc9100e" - ], - "version": "==0.10.0" - } - } + "develop": {} } diff --git a/README.md b/README.md index f814680..69f53b1 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Embedded Unit Converter -Embed a small bit of code that converts between units of measure, e.g. +Embed a small bit of code that converts between units of measure, e.g. Fahrenheit to Celsius. An example of a Rust library that is embeddable in Python. diff --git a/test.py b/test.py index b45758e..9140f86 100644 --- a/test.py +++ b/test.py @@ -1,5 +1,20 @@ import unit_converter +def python_unit_converter(celsius): + return celsius * 1.8 + 32.0 + + def test_using_unit_converter(): assert unit_converter.convert_celsius_to_fahrenheit(25.0) == 77.0 + assert python_unit_converter(25.0) == 77.0 + + +def test_using_python(benchmark): + result = benchmark(python_unit_converter, 25.0) + assert result == 77.0 + + +def test_using_rust(benchmark): + result = benchmark(unit_converter.convert_celsius_to_fahrenheit, 25.0) + assert result == 77.0