From ed93bdf4191322d1dba6c174710d1c3f22aa8aa9 Mon Sep 17 00:00:00 2001 From: fake-afik <153473227+fake-afik@users.noreply.github.com> Date: Sun, 10 Dec 2023 18:24:23 -0800 Subject: [PATCH 01/10] Create bubble_sort_2.py another bubble! --- bubble_sort_2.py | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 bubble_sort_2.py diff --git a/bubble_sort_2.py b/bubble_sort_2.py new file mode 100644 index 0000000..ba98eb1 --- /dev/null +++ b/bubble_sort_2.py @@ -0,0 +1,8 @@ +def sorter2(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 From 375b979d6b386f3263cd6bd7931df35f59a53c91 Mon Sep 17 00:00:00 2001 From: "afik.cohen" Date: Thu, 14 Dec 2023 21:48:12 -0800 Subject: [PATCH 02/10] add workflow --- .github/workflows/codeflash.yml | 2 +- .github/workflows/optimize.yml | 33 +++++++++++++++++++++++++++++++++ pyproject.toml | 22 ++++++++++++++++++++++ 3 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/optimize.yml create mode 100644 pyproject.toml diff --git a/.github/workflows/codeflash.yml b/.github/workflows/codeflash.yml index 366b6a3..efb0045 100644 --- a/.github/workflows/codeflash.yml +++ b/.github/workflows/codeflash.yml @@ -30,4 +30,4 @@ jobs: id: optimize_code run: | poetry env use python - poetry run codeflash --test-framework unittest --test-root code_to_optimize/tests/unittest + poetry run codeflash diff --git a/.github/workflows/optimize.yml b/.github/workflows/optimize.yml new file mode 100644 index 0000000..366b6a3 --- /dev/null +++ b/.github/workflows/optimize.yml @@ -0,0 +1,33 @@ +name: CodeFlash + +on: + pull_request: + workflow_dispatch: + +jobs: + optimize: + name: Optimize new code in this PR + runs-on: ubuntu-latest + env: + CODEFLASH_API_KEY: ${{ secrets.CODEFLASH_API_KEY }} + CODEFLASH_AI_KEY: ${{ secrets.CODEFLASH_AI_KEY }} + PR_NUMBER: ${{ github.event.number }} + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + token: ${{ secrets.GITHUB_TOKEN }} + - name: Set up Python 3.11 + uses: actions/setup-python@v4 + with: + python-version: 3.11.6 + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install poetry + poetry install + - name: Run CodeFlash to optimize code + id: optimize_code + run: | + poetry env use python + poetry run codeflash --test-framework unittest --test-root code_to_optimize/tests/unittest diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..b923efb --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,22 @@ +[tool.poetry] +name = "my-best-repo" +version = "0.1.0" +description = "" +authors = ["afik.cohen "] +readme = "README.md" + +[tool.poetry.dependencies] +python = "^3.10" +codeflash = {url = "https://www.dropbox.com/scl/fi/nif03u6oj327bn476h11i/codeflash-0.4.3.post1.dev0-50ba298-py3-none-any.whl?rlkey=uoy9h6wcjtktds84idqjkdmza&dl=1"} + + +[build-system] +requires = ["poetry-core"] +build-backend = "poetry.core.masonry.api" + + +[tool.codeflash] +root = "/Users/afik_cohen/repos/tacit/my-best-repo" +test-root = "/Users/afik_cohen/repos/tacit/my-best-repo/tests/pytests/" +test-framework = "pytest" +ignore-paths = ["tests/"] From dd7250cb9d4d2f4e69cc0e581b9f345f6e7d59f9 Mon Sep 17 00:00:00 2001 From: "afik.cohen" Date: Thu, 14 Dec 2023 21:49:21 -0800 Subject: [PATCH 03/10] delete dup workflow --- .github/workflows/optimize.yml | 33 --------------------------------- 1 file changed, 33 deletions(-) delete mode 100644 .github/workflows/optimize.yml diff --git a/.github/workflows/optimize.yml b/.github/workflows/optimize.yml deleted file mode 100644 index 366b6a3..0000000 --- a/.github/workflows/optimize.yml +++ /dev/null @@ -1,33 +0,0 @@ -name: CodeFlash - -on: - pull_request: - workflow_dispatch: - -jobs: - optimize: - name: Optimize new code in this PR - runs-on: ubuntu-latest - env: - CODEFLASH_API_KEY: ${{ secrets.CODEFLASH_API_KEY }} - CODEFLASH_AI_KEY: ${{ secrets.CODEFLASH_AI_KEY }} - PR_NUMBER: ${{ github.event.number }} - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - token: ${{ secrets.GITHUB_TOKEN }} - - name: Set up Python 3.11 - uses: actions/setup-python@v4 - with: - python-version: 3.11.6 - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install poetry - poetry install - - name: Run CodeFlash to optimize code - id: optimize_code - run: | - poetry env use python - poetry run codeflash --test-framework unittest --test-root code_to_optimize/tests/unittest From 63433aa9e21363474c45b9b278b9cec69fc8bb4d Mon Sep 17 00:00:00 2001 From: "afik.cohen" Date: Thu, 14 Dec 2023 21:58:27 -0800 Subject: [PATCH 04/10] fix toml --- pyproject.toml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index b923efb..d40f27d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,16 +7,18 @@ readme = "README.md" [tool.poetry.dependencies] python = "^3.10" -codeflash = {url = "https://www.dropbox.com/scl/fi/nif03u6oj327bn476h11i/codeflash-0.4.3.post1.dev0-50ba298-py3-none-any.whl?rlkey=uoy9h6wcjtktds84idqjkdmza&dl=1"} +[tool.poetry.dependencies.codeflash] +url = "https://www.dropbox.com/scl/fi/nif03u6oj327bn476h11i/codeflash-0.4.3.post1.dev0-50ba298-py3-none-any.whl?rlkey=uoy9h6wcjtktds84idqjkdmza&dl=1" + [build-system] requires = ["poetry-core"] build-backend = "poetry.core.masonry.api" [tool.codeflash] -root = "/Users/afik_cohen/repos/tacit/my-best-repo" -test-root = "/Users/afik_cohen/repos/tacit/my-best-repo/tests/pytests/" +root = "." +test-root = "tests" test-framework = "pytest" -ignore-paths = ["tests/"] +ignore-paths = [] From cb73599d95bbfdcdd92872df4c09e804dbdc37ad Mon Sep 17 00:00:00 2001 From: "afik.cohen" Date: Thu, 14 Dec 2023 22:20:41 -0800 Subject: [PATCH 05/10] add tests root --- tests/__init__.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/__init__.py diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 From 1b33c5056776dc384541f000f33ba4fa22847e64 Mon Sep 17 00:00:00 2001 From: "afik.cohen" Date: Fri, 5 Jan 2024 13:00:21 -0800 Subject: [PATCH 06/10] Another bubble 3! --- bubble_sort_3.py | 8 ++++++++ pyproject.toml | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 bubble_sort_3.py diff --git a/bubble_sort_3.py b/bubble_sort_3.py new file mode 100644 index 0000000..ba98eb1 --- /dev/null +++ b/bubble_sort_3.py @@ -0,0 +1,8 @@ +def sorter2(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 diff --git a/pyproject.toml b/pyproject.toml index d40f27d..383876b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,7 +10,7 @@ python = "^3.10" [tool.poetry.dependencies.codeflash] -url = "https://www.dropbox.com/scl/fi/nif03u6oj327bn476h11i/codeflash-0.4.3.post1.dev0-50ba298-py3-none-any.whl?rlkey=uoy9h6wcjtktds84idqjkdmza&dl=1" +url = "https://www.dropbox.com/scl/fi/o6xuo4vxrizli0nz80jra/codeflash-0.5.0.post95.dev0-a60d62c-py3-none-any.whl?rlkey=7r8gbrp2q5cs5mj8u8cuecju2&dl=1" [build-system] requires = ["poetry-core"] From 3170f0706ea2b2b84d72bab69f767fc35cd35526 Mon Sep 17 00:00:00 2001 From: "afik.cohen" Date: Fri, 5 Jan 2024 14:48:24 -0800 Subject: [PATCH 07/10] Use diff codeflash url --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 383876b..540361b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,7 +10,7 @@ python = "^3.10" [tool.poetry.dependencies.codeflash] -url = "https://www.dropbox.com/scl/fi/o6xuo4vxrizli0nz80jra/codeflash-0.5.0.post95.dev0-a60d62c-py3-none-any.whl?rlkey=7r8gbrp2q5cs5mj8u8cuecju2&dl=1" +url = "https://www.dropbox.com/scl/fi/cc9wktjof4fx6888l2kxe/codeflash-0.0.0-py3-none-any.whl?rlkey=d5jpchx11vlj3l959faw8uqgh&dl=1" [build-system] requires = ["poetry-core"] From dddad9965f10932ce5b04f8b9f32cc1ba4591ad2 Mon Sep 17 00:00:00 2001 From: fake-afik <153473227+fake-afik@users.noreply.github.com> Date: Mon, 5 Feb 2024 17:04:42 -0800 Subject: [PATCH 08/10] Update bubble_sort_2.py Co-authored-by: codeflash-ai[bot] <148906541+codeflash-ai[bot]@users.noreply.github.com> --- bubble_sort_2.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/bubble_sort_2.py b/bubble_sort_2.py index ba98eb1..d4ee3a5 100644 --- a/bubble_sort_2.py +++ b/bubble_sort_2.py @@ -1,8 +1,3 @@ def sorter2(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 + arr.sort() return arr From 52d30e0c021ab11fcb4f9d2da987a33b2d39d602 Mon Sep 17 00:00:00 2001 From: "codeflash-ai[bot]" <148906541+codeflash-ai[bot]@users.noreply.github.com> Date: Wed, 21 Feb 2024 19:55:25 +0000 Subject: [PATCH 09/10] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20Speed=20up=20sorter(?= =?UTF-8?q?)=20by=204211531.56=20in=20PR=20#1=20The=20function=20you=20pro?= =?UTF-8?q?vided,=20sorter,=20is=20already=20using=20Python's=20built-in?= =?UTF-8?q?=20sort=20function=20which=20has=20a=20time=20complexity=20of?= =?UTF-8?q?=20O(n=20log=20n),=20where=20n=20is=20a=20number=20of=20element?= =?UTF-8?q?s=20in=20the=20array.=20This=20is=20the=20fastest=20achievable?= =?UTF-8?q?=20sorting=20complexity=20for=20comparison-based=20sorts.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit However, if you want to achieve a marginal speed increase, writing this in-place might help. Here's an alternative version using list comprehension. Although this does not improve the time complexity, it gives a Pythonic touch: ```python def sorter(arr): return sorted(arr) ``` Again, this command returns a new sorted list and does not modify the original list. If you want to sort the list in-place, you only have the original function: Please note that sorting time complexity cannot be improved further than O(n log n) using comparison-based sorting algorithms. To really optimize this function, you would need a guarantee about the content of your data, for example, if your array only contained integers in a particular range, then you could use counting sort or radix sort, which can have a time complexity of O(n). --- code_to_optimize/bubble_sort.py | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 code_to_optimize/bubble_sort.py diff --git a/code_to_optimize/bubble_sort.py b/code_to_optimize/bubble_sort.py new file mode 100644 index 0000000..3a904b0 --- /dev/null +++ b/code_to_optimize/bubble_sort.py @@ -0,0 +1,5 @@ +def sorter(arr): + arr.sort() + return arr + + From 7ebba442b79b75c5bb7b240bed6126d7f429c257 Mon Sep 17 00:00:00 2001 From: fake-afik <153473227+fake-afik@users.noreply.github.com> Date: Mon, 25 Mar 2024 13:55:44 -0700 Subject: [PATCH 10/10] =?UTF-8?q?Revert=20"=E2=9A=A1=EF=B8=8F=20Speed=20up?= =?UTF-8?q?=20`sorter()`=20by=204211531.56=20in=20PR=20#1=20(`new-sorter`)?= =?UTF-8?q?"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- code_to_optimize/bubble_sort.py | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 code_to_optimize/bubble_sort.py diff --git a/code_to_optimize/bubble_sort.py b/code_to_optimize/bubble_sort.py deleted file mode 100644 index 3a904b0..0000000 --- a/code_to_optimize/bubble_sort.py +++ /dev/null @@ -1,5 +0,0 @@ -def sorter(arr): - arr.sort() - return arr - -