Separate out the batching code.
This commit is contained in:
parent
bb55a922b9
commit
0369c3fb86
|
@ -0,0 +1,22 @@
|
|||
import random
|
||||
|
||||
import pytest
|
||||
|
||||
import unit_converter
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def batch_numbers():
|
||||
return [random.random() * 100 for x in range(1000)]
|
||||
|
||||
|
||||
def batch_python_unit_converter(temperatures):
|
||||
return [celsius * 1.8 + 32.0 for celsius in temperatures]
|
||||
|
||||
|
||||
def test_using_python_batch(benchmark, batch_numbers):
|
||||
benchmark(batch_python_unit_converter, batch_numbers)
|
||||
|
||||
|
||||
def test_using_rust_batch(benchmark, batch_numbers):
|
||||
benchmark(unit_converter.batch_convert_celsius_to_fahrenheit, batch_numbers)
|
15
test.py
15
test.py
|
@ -1,15 +1,8 @@
|
|||
import random
|
||||
|
||||
import pytest
|
||||
|
||||
import unit_converter
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def batch_numbers():
|
||||
return [random.random() * 100 for x in range(1000)]
|
||||
|
||||
|
||||
def python_unit_converter(celsius):
|
||||
return celsius * 1.8 + 32.0
|
||||
|
||||
|
@ -43,11 +36,3 @@ def test_using_rust(benchmark):
|
|||
temperature = random.random() * 100
|
||||
result = benchmark(unit_converter.convert_celsius_to_fahrenheit, temperature)
|
||||
assert round(result, 3) == round(python_unit_converter(temperature), 3)
|
||||
|
||||
|
||||
def test_using_python_batch(benchmark, batch_numbers):
|
||||
benchmark(batch_python_unit_converter, batch_numbers)
|
||||
|
||||
|
||||
def test_using_rust_batch(benchmark, batch_numbers):
|
||||
benchmark(unit_converter.batch_convert_celsius_to_fahrenheit, batch_numbers)
|
||||
|
|
Loading…
Reference in New Issue