Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
151 commits
Select commit Hold shift + click to select a range
3480718
initial implementation for pytest benchmark discovery
alvin-r Feb 25, 2025
7f917a0
Merge branch 'refs/heads/main' into pytest-benchmark
alvin-r Feb 27, 2025
133a9e3
initial implementation for tracing benchmarks using a plugin, and pro…
alvin-r Feb 28, 2025
2f26695
initial implementation of tracing benchmarks via the plugin
alvin-r Mar 4, 2025
32b0d3b
Merge branch 'main' into pytest-benchmark
alvin-r Mar 11, 2025
6b4b68a
basic version working on bubble sort
alvin-r Mar 11, 2025
887e3cb
initial attempt for codeflash_trace_decorator
alvin-r Mar 11, 2025
84bd0f0
improvements
alvin-r Mar 12, 2025
1c3919d
Merge branch 'refs/heads/main' into codeflash-trace-decorator
alvin-r Mar 12, 2025
c4694b7
work on new replay_test logic
alvin-r Mar 12, 2025
c150c05
Merge branch 'main' into codeflash-trace-decorator
alvin-r Mar 14, 2025
1801d41
initial replay test version working
alvin-r Mar 14, 2025
88a11d3
Merge branch 'main' into codeflash-trace-decorator
alvin-r Mar 14, 2025
f7466a5
replay test functionality working for functions, methods, static meth…
alvin-r Mar 14, 2025
4c19e6f
restored overwritten logic
alvin-r Mar 14, 2025
7eba031
functioning end to end, gets the funciton impact on benchmarks
alvin-r Mar 18, 2025
896aa52
modified printing of results, handle errors when collecting benchmarks
alvin-r Mar 19, 2025
ad17de4
tests pass
alvin-r Mar 19, 2025
92e6bf5
revert pyproject.toml
alvin-r Mar 19, 2025
4784723
mypy fixes
alvin-r Mar 19, 2025
5f05711
Merge branch 'main' into codeflash-trace-decorator
alvin-r Mar 19, 2025
b77a979
import changes
alvin-r Mar 20, 2025
8878baf
Merge branch 'pytest-plugin-blocker' into codeflash-trace-decorator
alvin-r Mar 20, 2025
0c2a3b6
removed benchmark skip command
alvin-r Mar 20, 2025
9a41bdd
shifted benchmark class in plugin, improved display of benchmark info
alvin-r Mar 20, 2025
5577cd5
cleanup tests better
alvin-r Mar 20, 2025
83f1c1c
Merge branch 'main' into codeflash-trace-decorator
alvin-r Mar 20, 2025
80730f9
modified paths in test
alvin-r Mar 20, 2025
d610f8c
typing fix
alvin-r Mar 20, 2025
93f583c
typing fix for 3.9
alvin-r Mar 21, 2025
d422e35
typing fix for 3.9
alvin-r Mar 21, 2025
d664040
Merge branch 'main' into codeflash-trace-decorator
alvin-r Mar 21, 2025
1637810
works with multithreading, added test
alvin-r Mar 24, 2025
684acf8
Merge branch 'refs/heads/main' into codeflash-trace-decorator
alvin-r Mar 24, 2025
6180c9d
refactored get_function_benchmark_timings and get_benchmark_timings i…
alvin-r Mar 25, 2025
fa93df6
Merge branch 'refs/heads/main' into codeflash-trace-decorator
alvin-r Mar 25, 2025
67d3f19
fixed isort
alvin-r Mar 25, 2025
f4be9be
modified PR info
alvin-r Mar 26, 2025
77f43a5
mypy fix
alvin-r Mar 26, 2025
da6385f
use dill instead of pickle
alvin-r Mar 26, 2025
f34f22f
modified the benchmarking approach. codeflash_trace and codeflash_ben…
alvin-r Mar 28, 2025
57b80ec
started implementing group by benchmark
alvin-r Mar 28, 2025
87ad743
Merge branch 'refs/heads/merge_test_results_into_models' into codefla…
alvin-r Mar 28, 2025
d03ed96
Merge branch 'merge_test_results_into_models' into codeflash-trace-de…
alvin-r Mar 28, 2025
8d95b18
Merge branch 'main' into codeflash-trace-decorator
alvin-r Mar 28, 2025
56e3447
reworked matching benchmark key to test results.
alvin-r Mar 31, 2025
5a34697
Merge branch 'main' into codeflash-trace-decorator
alvin-r Apr 1, 2025
5f86bdd
PRAGMA journal to memory to make it faster
alvin-r Apr 1, 2025
20890fa
Merge branch 'main' into codeflash-trace-decorator
alvin-r Apr 1, 2025
9764c25
benchmarks root must be subdir of tests root
alvin-r Apr 1, 2025
d703b13
replay tests are now grouped by benchmark file. each benchmark test f…
alvin-r Apr 1, 2025
14c33f9
Merge branch 'main' into codeflash-trace-decorator
alvin-r Apr 1, 2025
c6a201b
Merge branch 'main' into codeflash-trace-decorator
alvin-r Apr 1, 2025
30ec0c4
Use module path instead of file path for benchmarks, improved display…
alvin-r Apr 2, 2025
cf00212
Merge branch 'refs/heads/main' into codeflash-trace-decorator
alvin-r Apr 2, 2025
bb9c5db
benchmark flow is working. changed paths to use module_path instead o…
alvin-r Apr 2, 2025
7d9c4e1
Merge branch 'main' into codeflash-trace-decorator
alvin-r Apr 2, 2025
1928dc4
fixed string error
alvin-r Apr 2, 2025
217e239
fixed mypy error
alvin-r Apr 2, 2025
96dd780
new end to end test for benchmarking bubble sort
alvin-r Apr 2, 2025
5785875
renamed test
alvin-r Apr 2, 2025
d656d3b
fixed e2e test
alvin-r Apr 2, 2025
4d0eb3d
printing issues on github actions
alvin-r Apr 2, 2025
6100620
attempt to use horizontals for rows
alvin-r Apr 2, 2025
21a79eb
added row lines
alvin-r Apr 2, 2025
b374b6e
made benchmarks-root use resolve()
alvin-r Apr 3, 2025
27a6488
handled edge case for instrumenting codeflash trace
alvin-r Apr 3, 2025
4a24f2c
fixed slight bug with formatting table
alvin-r Apr 3, 2025
9de664b
improved file removal after errors
alvin-r Apr 3, 2025
a8d4fda
fixed a return bug
alvin-r Apr 4, 2025
4d53330
Merge branch 'jedi_ctx_fix' into codeflash-trace-decorator
alvin-r Apr 4, 2025
c82a3a3
Merge branch 'refs/heads/main' into codeflash-trace-decorator
alvin-r Apr 7, 2025
1f3fcff
Support recursive functions, and @benchmark / @pytest.mark.benchmark …
alvin-r Apr 7, 2025
fe63652
basic pickle patch version working
alvin-r Apr 8, 2025
d653d0d
draft of end to end test
alvin-r Apr 8, 2025
a73b541
initial implementation for pytest benchmark discovery
alvin-r Feb 25, 2025
965e2c8
initial implementation for tracing benchmarks using a plugin, and pro…
alvin-r Feb 28, 2025
7590c29
initial implementation of tracing benchmarks via the plugin
alvin-r Mar 4, 2025
034bed3
basic version working on bubble sort
alvin-r Mar 11, 2025
1f3fd4d
initial attempt for codeflash_trace_decorator
alvin-r Mar 11, 2025
5faccd8
improvements
alvin-r Mar 12, 2025
d6217e8
work on new replay_test logic
alvin-r Mar 12, 2025
26b2c4f
initial replay test version working
alvin-r Mar 14, 2025
adffb9d
replay test functionality working for functions, methods, static meth…
alvin-r Mar 14, 2025
f9144ec
restored overwritten logic
alvin-r Mar 14, 2025
c29c8bf
functioning end to end, gets the funciton impact on benchmarks
alvin-r Mar 18, 2025
54fe71f
modified printing of results, handle errors when collecting benchmarks
alvin-r Mar 19, 2025
5fd112a
tests pass
alvin-r Mar 19, 2025
8194554
revert pyproject.toml
alvin-r Mar 19, 2025
4c1d2af
mypy fixes
alvin-r Mar 19, 2025
6e676e9
import changes
alvin-r Mar 20, 2025
62f3b36
removed benchmark skip command
alvin-r Mar 20, 2025
a614972
shifted benchmark class in plugin, improved display of benchmark info
alvin-r Mar 20, 2025
82cb7a9
cleanup tests better
alvin-r Mar 20, 2025
7601895
modified paths in test
alvin-r Mar 20, 2025
4d69427
typing fix
alvin-r Mar 20, 2025
ebe3e12
typing fix for 3.9
alvin-r Mar 21, 2025
0449d0d
typing fix for 3.9
alvin-r Mar 21, 2025
baac964
works with multithreading, added test
alvin-r Mar 24, 2025
357f586
refactored get_function_benchmark_timings and get_benchmark_timings i…
alvin-r Mar 25, 2025
9efa47f
fixed isort
alvin-r Mar 25, 2025
64b4c64
modified PR info
alvin-r Mar 26, 2025
4c61de9
mypy fix
alvin-r Mar 26, 2025
eda0d46
use dill instead of pickle
alvin-r Mar 26, 2025
a82e9f0
modified the benchmarking approach. codeflash_trace and codeflash_ben…
alvin-r Mar 28, 2025
582bea0
started implementing group by benchmark
alvin-r Mar 28, 2025
e5a8260
reworked matching benchmark key to test results.
alvin-r Mar 31, 2025
0937329
PRAGMA journal to memory to make it faster
alvin-r Apr 1, 2025
ed8f5ef
benchmarks root must be subdir of tests root
alvin-r Apr 1, 2025
75c1be7
replay tests are now grouped by benchmark file. each benchmark test f…
alvin-r Apr 1, 2025
b3c8320
Use module path instead of file path for benchmarks, improved display…
alvin-r Apr 2, 2025
972ef46
benchmark flow is working. changed paths to use module_path instead o…
alvin-r Apr 2, 2025
06b3818
fixed string error
alvin-r Apr 2, 2025
37577e7
fixed mypy error
alvin-r Apr 2, 2025
5c30d3e
new end to end test for benchmarking bubble sort
alvin-r Apr 2, 2025
906e434
renamed test
alvin-r Apr 2, 2025
821fa47
fixed e2e test
alvin-r Apr 2, 2025
41f7e0a
printing issues on github actions
alvin-r Apr 2, 2025
c20f29a
attempt to use horizontals for rows
alvin-r Apr 2, 2025
d1a8d25
added row lines
alvin-r Apr 2, 2025
705105c
made benchmarks-root use resolve()
alvin-r Apr 3, 2025
26546de
handled edge case for instrumenting codeflash trace
alvin-r Apr 3, 2025
0c04adf
fixed slight bug with formatting table
alvin-r Apr 3, 2025
30d32bb
improved file removal after errors
alvin-r Apr 3, 2025
c997b90
fixed a return bug
alvin-r Apr 4, 2025
d6ed1c3
Support recursive functions, and @benchmark / @pytest.mark.benchmark …
alvin-r Apr 7, 2025
a4c4c2d
Merge remote-tracking branch 'origin/codeflash-trace-decorator' into …
alvin-r Apr 10, 2025
40e416e
Merge branch 'refs/heads/main' into codeflash-trace-decorator
alvin-r Apr 11, 2025
3158f9c
end to end test that proves picklepatcher works. example shown is a s…
alvin-r Apr 11, 2025
9578854
Merge branch 'main' into codeflash-trace-decorator
alvin-r Apr 11, 2025
4bb0aad
minor fix for removing files
alvin-r Apr 11, 2025
790d77c
fixes to sync with main
alvin-r Apr 11, 2025
fce641e
Merge branch 'main' into codeflash-trace-decorator
alvin-r Apr 11, 2025
b70c4c9
Merge branch 'main' into codeflash-trace-decorator
alvin-r Apr 15, 2025
28fd746
cmd init changes
alvin-r Apr 15, 2025
4e8483b
created benchmarks for codeflash, modified codeflash-optimize to use …
alvin-r Apr 16, 2025
efc91d6
Merge branch 'main' into codeflash-trace-decorator
alvin-r Apr 16, 2025
0680f79
added benchmarks root
alvin-r Apr 16, 2025
583b464
removed comment
alvin-r Apr 16, 2025
1eaaad7
debugging
alvin-r Apr 16, 2025
ab9079b
debugging
alvin-r Apr 16, 2025
d7274ec
removed benchmark-skip
alvin-r Apr 16, 2025
a624221
added pytest-benchmark as dependency
alvin-r Apr 16, 2025
605d078
updated pyproject
alvin-r Apr 16, 2025
78871fe
gha failing on multithreaded t est
alvin-r Apr 16, 2025
0146d82
line number test is off by 1 for python versions 39 and 310, removed …
alvin-r Apr 17, 2025
6c1a369
Merge branch 'main' into codeflash-trace-decorator
alvin-r Apr 17, 2025
3017ccf
100 max function calls before flushing to disk instead of 1000
alvin-r Apr 17, 2025
f14cf01
skip multithreaded benchmark test if machine is single threaded (fixe…
alvin-r Apr 17, 2025
e5ca10f
marked multithreaded trace benchmarks test to be skipped during CI as…
alvin-r Apr 17, 2025
683c9f6
shift check for pickle placerholder access error in comparator
alvin-r Apr 17, 2025
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/codeflash-optimize.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,4 @@ jobs:
id: optimize_code
run: |
source .venv/bin/activate
poetry run codeflash
poetry run codeflash --benchmark
41 changes: 41 additions & 0 deletions .github/workflows/end-to-end-test-benchmark-bubblesort.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: end-to-end-test

on:
pull_request:
workflow_dispatch:

jobs:
benchmark-bubble-sort-optimization:
runs-on: ubuntu-latest
env:
CODEFLASH_AIS_SERVER: prod
POSTHOG_API_KEY: ${{ secrets.POSTHOG_API_KEY }}
CODEFLASH_API_KEY: ${{ secrets.CODEFLASH_API_KEY }}
COLUMNS: 110
MAX_RETRIES: 3
RETRY_DELAY: 5
EXPECTED_IMPROVEMENT_PCT: 5
CODEFLASH_END_TO_END: 1
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Python 3.11 for CLI
uses: astral-sh/setup-uv@v5
with:
python-version: 3.11.6

- name: Install dependencies (CLI)
run: |
uv tool install poetry
uv venv
source .venv/bin/activate
poetry install --with dev
- name: Run Codeflash to optimize code
id: optimize_code_with_benchmarks
run: |
source .venv/bin/activate
poetry run python tests/scripts/end_to_end_test_benchmark_sort.py
2 changes: 1 addition & 1 deletion .github/workflows/unit-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
run: uvx poetry install --with dev

- name: Unit tests
run: uvx poetry run pytest tests/ --cov --cov-report=xml
run: uvx poetry run pytest tests/ --cov --cov-report=xml --benchmark-skip -m "not ci_skip"

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v5
Expand Down
2 changes: 1 addition & 1 deletion code_to_optimize/bubble_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ def sorter(arr):
arr[j] = arr[j + 1]
arr[j + 1] = temp
print(f"result: {arr}")
return arr
return arr
64 changes: 64 additions & 0 deletions code_to_optimize/bubble_sort_codeflash_trace.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
from codeflash.benchmarking.codeflash_trace import codeflash_trace
@codeflash_trace
def sorter(arr):
for i in range(len(arr)):
for j in range(len(arr) - 1):
if arr[j] > arr[j + 1]:
temp = arr[j]
arr[j] = arr[j + 1]
arr[j + 1] = temp
return arr

@codeflash_trace
def recursive_bubble_sort(arr, n=None):
# Initialize n if not provided
if n is None:
n = len(arr)

# Base case: if n is 1, the array is already sorted
if n == 1:
return arr

# One pass of bubble sort - move the largest element to the end
for i in range(n - 1):
if arr[i] > arr[i + 1]:
arr[i], arr[i + 1] = arr[i + 1], arr[i]

# Recursively sort the remaining n-1 elements
return recursive_bubble_sort(arr, n - 1)

class Sorter:
@codeflash_trace
def __init__(self, arr):
self.arr = arr
@codeflash_trace
def sorter(self, multiplier):
for i in range(len(self.arr)):
for j in range(len(self.arr) - 1):
if self.arr[j] > self.arr[j + 1]:
temp = self.arr[j]
self.arr[j] = self.arr[j + 1]
self.arr[j + 1] = temp
return self.arr * multiplier

@staticmethod
@codeflash_trace
def sort_static(arr):
for i in range(len(arr)):
for j in range(len(arr) - 1):
if arr[j] > arr[j + 1]:
temp = arr[j]
arr[j] = arr[j + 1]
arr[j + 1] = temp
return arr

@classmethod
@codeflash_trace
def sort_class(cls, arr):
for i in range(len(arr)):
for j in range(len(arr) - 1):
if arr[j] > arr[j + 1]:
temp = arr[j]
arr[j] = arr[j + 1]
arr[j + 1] = temp
return arr
23 changes: 23 additions & 0 deletions code_to_optimize/bubble_sort_multithread.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# from code_to_optimize.bubble_sort_codeflash_trace import sorter
from code_to_optimize.bubble_sort_codeflash_trace import sorter
import concurrent.futures


def multithreaded_sorter(unsorted_lists: list[list[int]]) -> list[list[int]]:
# Create a list to store results in the correct order
sorted_lists = [None] * len(unsorted_lists)

# Use ThreadPoolExecutor to manage threads
with concurrent.futures.ThreadPoolExecutor(max_workers=2) as executor:
# Submit all sorting tasks and map them to their original indices
future_to_index = {
executor.submit(sorter, unsorted_list): i
for i, unsorted_list in enumerate(unsorted_lists)
}

# Collect results as they complete
for future in concurrent.futures.as_completed(future_to_index):
index = future_to_index[future]
sorted_lists[index] = future.result()

return sorted_lists
18 changes: 18 additions & 0 deletions code_to_optimize/bubble_sort_picklepatch_test_unused_socket.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

from codeflash.benchmarking.codeflash_trace import codeflash_trace


@codeflash_trace
def bubble_sort_with_unused_socket(data_container):
# Extract the list to sort, leaving the socket untouched
numbers = data_container.get('numbers', []).copy()

return sorted(numbers)

@codeflash_trace
def bubble_sort_with_used_socket(data_container):
# Extract the list to sort, leaving the socket untouched
numbers = data_container.get('numbers', []).copy()
socket = data_container.get('socket')
socket.send("Hello from the optimized function!")
return sorted(numbers)
46 changes: 46 additions & 0 deletions code_to_optimize/bubble_sort_picklepatch_test_used_socket.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from codeflash.benchmarking.codeflash_trace import codeflash_trace

@codeflash_trace
def bubble_sort_with_used_socket(data_container):
"""
Performs a bubble sort on a list within the data_container. The data container has the following schema:
- 'numbers' (list): The list to be sorted.
- 'socket' (socket): A socket
Args:
data_container: A dictionary with at least 'numbers' (list) and 'socket' keys
Returns:
list: The sorted list of numbers
"""
# Extract the list to sort and socket
numbers = data_container.get('numbers', []).copy()
socket = data_container.get('socket')

# Track swap count
swap_count = 0

# Classic bubble sort implementation
n = len(numbers)
for i in range(n):
# Flag to optimize by detecting if no swaps occurred
swapped = False

# Last i elements are already in place
for j in range(0, n - i - 1):
# Swap if the element is greater than the next element
if numbers[j] > numbers[j + 1]:
# Perform the swap
numbers[j], numbers[j + 1] = numbers[j + 1], numbers[j]
swapped = True
swap_count += 1

# If no swapping occurred in this pass, the list is sorted
if not swapped:
break

# Send final summary
summary = f"Bubble sort completed with {swap_count} swaps"
socket.send(summary.encode())

return numbers
28 changes: 28 additions & 0 deletions code_to_optimize/process_and_bubble_sort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from code_to_optimize.bubble_sort import sorter


def calculate_pairwise_products(arr):
"""
Calculate the average of all pairwise products in the array.
"""
sum_of_products = 0
count = 0

for i in range(len(arr)):
for j in range(len(arr)):
if i != j:
sum_of_products += arr[i] * arr[j]
count += 1

# The average of all pairwise products
return sum_of_products / count if count > 0 else 0


def compute_and_sort(arr):
# Compute pairwise sums average
pairwise_average = calculate_pairwise_products(arr)

# Call sorter function
sorter(arr.copy())

return pairwise_average
28 changes: 28 additions & 0 deletions code_to_optimize/process_and_bubble_sort_codeflash_trace.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from code_to_optimize.bubble_sort import sorter
from codeflash.benchmarking.codeflash_trace import codeflash_trace

def calculate_pairwise_products(arr):
"""
Calculate the average of all pairwise products in the array.
"""
sum_of_products = 0
count = 0

for i in range(len(arr)):
for j in range(len(arr)):
if i != j:
sum_of_products += arr[i] * arr[j]
count += 1

# The average of all pairwise products
return sum_of_products / count if count > 0 else 0

@codeflash_trace
def compute_and_sort(arr):
# Compute pairwise sums average
pairwise_average = calculate_pairwise_products(arr)

# Call sorter function
sorter(arr.copy())

return pairwise_average
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import pytest

from code_to_optimize.bubble_sort import sorter


def test_sort(benchmark):
result = benchmark(sorter, list(reversed(range(500))))
assert result == list(range(500))

# This should not be picked up as a benchmark test
def test_sort2():
result = sorter(list(reversed(range(500))))
assert result == list(range(500))
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from code_to_optimize.process_and_bubble_sort import compute_and_sort
from code_to_optimize.bubble_sort import sorter
def test_compute_and_sort(benchmark):
result = benchmark(compute_and_sort, list(reversed(range(500))))
assert result == 62208.5

def test_no_func(benchmark):
benchmark(sorter, list(reversed(range(500))))
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from code_to_optimize.bubble_sort_multithread import multithreaded_sorter

def test_benchmark_sort(benchmark):
benchmark(multithreaded_sorter, [list(range(1000)) for i in range (10)])
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import socket

from code_to_optimize.bubble_sort_picklepatch_test_unused_socket import bubble_sort_with_unused_socket
from code_to_optimize.bubble_sort_picklepatch_test_used_socket import bubble_sort_with_used_socket

def test_socket_picklepatch(benchmark):
s1, s2 = socket.socketpair()
data = {
"numbers": list(reversed(range(500))),
"socket": s1
}
benchmark(bubble_sort_with_unused_socket, data)

def test_used_socket_picklepatch(benchmark):
s1, s2 = socket.socketpair()
data = {
"numbers": list(reversed(range(500))),
"socket": s1
}
benchmark(bubble_sort_with_used_socket, data)
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import pytest

from code_to_optimize.bubble_sort_codeflash_trace import sorter, Sorter


def test_sort(benchmark):
result = benchmark(sorter, list(reversed(range(500))))
assert result == list(range(500))

# This should not be picked up as a benchmark test
def test_sort2():
result = sorter(list(reversed(range(500))))
assert result == list(range(500))

def test_class_sort(benchmark):
obj = Sorter(list(reversed(range(100))))
result1 = benchmark(obj.sorter, 2)

def test_class_sort2(benchmark):
result2 = benchmark(Sorter.sort_class, list(reversed(range(100))))

def test_class_sort3(benchmark):
result3 = benchmark(Sorter.sort_static, list(reversed(range(100))))

def test_class_sort4(benchmark):
result4 = benchmark(Sorter, [1,2,3])
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from code_to_optimize.process_and_bubble_sort_codeflash_trace import compute_and_sort
from code_to_optimize.bubble_sort_codeflash_trace import sorter
def test_compute_and_sort(benchmark):
result = benchmark(compute_and_sort, list(reversed(range(500))))
assert result == 62208.5

def test_no_func(benchmark):
benchmark(sorter, list(reversed(range(500))))
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from code_to_optimize.bubble_sort_codeflash_trace import recursive_bubble_sort


def test_recursive_sort(benchmark):
result = benchmark(recursive_bubble_sort, list(reversed(range(500))))
assert result == list(range(500))
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import pytest
from code_to_optimize.bubble_sort_codeflash_trace import sorter

def test_benchmark_sort(benchmark):
@benchmark
def do_sort():
sorter(list(reversed(range(500))))

@pytest.mark.benchmark(group="benchmark_decorator")
def test_pytest_mark(benchmark):
benchmark(sorter, list(reversed(range(500))))
Empty file.
Loading
Loading