Skip to content

Commit

Permalink
Move benchmark as a mix task
Browse files Browse the repository at this point in the history
  • Loading branch information
jaeyson committed Apr 12, 2024
1 parent b6c78e0 commit f955930
Show file tree
Hide file tree
Showing 17 changed files with 333 additions and 126 deletions.
14 changes: 14 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "mix" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
labels:
- "hex"
- "dependencies"
30 changes: 14 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,20 @@ jobs:
strategy:
matrix:
include:
# - elixir: 1.11.x
# otp: 22
# - elixir: 1.11.x
# otp: 23
# - elixir: 1.12.x
# otp: 23
# - elixir: 1.13.x
# otp: 24
- elixir: 1.11.x
otp: 22
- elixir: 1.11.x
otp: 23
- elixir: 1.12.x
otp: 23
- elixir: 1.13.x
otp: 24
- elixir: 1.14.x
otp: 25
- elixir: 1.15.x
otp: 26
- elixir: 1.16.x
otp: 26
warnings_as_errors: true
static_analysis: true
env:
Expand All @@ -38,7 +42,7 @@ jobs:
if: "!contains(github.event.head_commit.message, '[skip ci]')"
steps:
- name: Checkout repo
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Setup Erlang/OTP & Elixir
uses: erlef/setup-beam@v1
Expand All @@ -47,7 +51,7 @@ jobs:
elixir-version: ${{ matrix.elixir }}

- name: Cache artifacts
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: |
deps
Expand All @@ -73,9 +77,3 @@ jobs:
run: mix coveralls.github
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Publish to Hex
if: "contains(github.event.head_commit.message, '[publish to hex]')"
run: |
mix hex.config api_key ${{ secrets.HEX_API_KEY }}
mix hex.publish --yes
28 changes: 28 additions & 0 deletions .github/workflows/hex.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: CI

on:
pull_request:
branches:
- main
push:
branches:
- main

jobs:
check_commit_message:
name: skips CI and prints cli message, without fail build badge
runs-on: ubuntu-latest
if: "contains(github.event.head_commit.message, '[skip ci]')"
steps:
- run: echo "no need to build, based from commit message"

publish_to_hex:
name: "Publish to Hex"
runs-on: ubuntu-latest

# doesn't contain "ci skip" in commit message
if: "!contains(github.event.head_commit.message, '[skip ci]')"
steps:
run: |
mix hex.config api_key ${{ secrets.HEX_API_KEY }}
mix hex.publish --yes
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ sample-*.tar
# Temporary files, for example, from tests.
/tmp/

# Benchmarks from benchee
/benchmarks/

.elixir_ls

.DS_Store
2 changes: 1 addition & 1 deletion .iex.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
alias FreecodecampElixir.AlgoProjects
alias FreecodecampElixir.BasicAlgo
alias FreecodecampElixir.IntermediateAlgo
alias FreecodecampElixir.Benchmarks

require Logger
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 0.2.0 (2024.12.04)

- Benchmarks as mix task
- Bump dependencies' versions
- Tidy docs

## 0.1.0 (2022.09.04)

* Initial release
- Initial release
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Solving exercises from Freecodecamp.org using Elixir programming language. Includes benchmarks and tests for every functions.

[//]: # "Badges"

[![Last Commit][commit-badge]](https://github.com/jaeyson/freecodecamp_elixir/commit/main)
[![Commit activity][pulse-badge]](https://github.com/jaeyson/freecodecamp_elixir/pulse)
[![Dependabot][dependabot-badge]](https://github.com/jaeyson/freecodecamp_elixir/pulls/app%2Fdependabot)
Expand Down Expand Up @@ -112,7 +113,6 @@ mix selective_test basic_algo intermediate_algo

# basic_algo = Basic Algorithm Scripting
# intermediate_algo = Intermediate Algorithm Scripting
# algo_projects = Algorithm Projects
```

## Generate `HTML` Docs
Expand All @@ -124,22 +124,22 @@ mix docs

## Benchmarks (using Benchee)

If you want to benchmark a specific function:

```bash
# NOTE: file path is at
# freecodecamp_elixir/benchmarks/basic_algo.exs
# view benchmark commands
mix help benchmark
```

# Example: change the function name from
# "mutation" to "repeat_string"
# BasicAlgo.run("mutation", HTML)
# or uncomment lines to use that instead
BasicAlgo.run("repeat_string", HTML)
```bash
# list available functions
mix benchmark --list
```

# you can use the default formatter (console)
BasicAlgo.run("repeat_string", Console)
```bash
# specific function
mix benchmark mutation
```

```bash
mix run benchmarks/basic_algo.exs
# benchmark results saved as html in "benchmarks/" directory
mix benchmark mutation --html
```
13 changes: 5 additions & 8 deletions coveralls.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
{
"skip_files": [
"benchmarks/",
"lib/mix/"
],
"terminal_options": {
"file_column_width": 60
}
}
"skip_files": ["lib/freecodecamp_elixir/benchmarks/", "lib/mix/"],
"terminal_options": {
"file_column_width": 60
}
}
6 changes: 0 additions & 6 deletions lib/freecodecamp_elixir/algo_projects.ex

This file was deleted.

4 changes: 2 additions & 2 deletions lib/freecodecamp_elixir/basic_algo.ex
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,8 @@ defmodule FreecodecampElixir.BasicAlgo do
end

@spec do_get_index_to_ins(non_neg_integer | nil) :: non_neg_integer
def do_get_index_to_ins(nil), do: 0
def do_get_index_to_ins(result), do: result
defp do_get_index_to_ins(nil), do: 0
defp do_get_index_to_ins(result), do: result

@doc """
Check if a string (first argument, `string`) ends with the
Expand Down
Loading

0 comments on commit f955930

Please sign in to comment.