Skip to content

Commit f34459a

Browse files
authored
Add benchmark (#33)
* Add benchmark
1 parent ac6c9e0 commit f34459a

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

.github/workflows/Benchmark.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Run benchmarks
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- "src/**"
7+
- "benchmark/**"
8+
- "Project.toml"
9+
- "benchmark/Project.toml"
10+
11+
permissions:
12+
contents: write
13+
issues: write
14+
pull-requests: write
15+
16+
concurrency:
17+
# Skip intermediate builds: always.
18+
# Cancel intermediate builds: only if it is a pull request build.
19+
group: ${{ github.workflow }}-${{ github.ref }}
20+
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}
21+
22+
jobs:
23+
benchmark:
24+
runs-on: ubuntu-latest
25+
steps:
26+
- uses: actions/checkout@v4
27+
- uses: julia-actions/setup-julia@latest
28+
with:
29+
version: 1
30+
- uses: julia-actions/julia-buildpkg@latest
31+
- name: Install dependencies
32+
run: julia -e 'using Pkg; pkg"add PkgBenchmark BenchmarkCI@0.1"'
33+
- name: Run benchmarks
34+
run: julia -e 'using BenchmarkCI; BenchmarkCI.judge(baseline="origin/main")'
35+
- name: Post results
36+
run: julia -e 'using BenchmarkCI; BenchmarkCI.postjudge()'
37+
env:
38+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

benchmark/Project.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[deps]
2+
ADNLPModels = "54578032-b7ea-4c30-94aa-7cbd1cce6c9a"
3+
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
4+
NLPModels = "a4795742-8479-5a88-8948-cc11e1c8c1a6"
5+
OptimizationProblems = "5049e819-d29b-5fba-b941-0eee7e64c1c6"

benchmark/benchmarks.jl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using BenchmarkTools, ADNLPModels, NLPModels
2+
using OptimizationProblems
3+
using TimerNLPModels
4+
5+
# Run locally with `tune!(SUITE)` and then `run(SUITE)`
6+
const SUITE = BenchmarkGroup()
7+
8+
for n in [100, 1000]
9+
g = zeros(n)
10+
SUITE["grad! ref"]["$n"] = @benchmarkable grad!(nlp, get_x0(nlp), $g) setup =
11+
(nlp = OptimizationProblems.ADNLPProblems.arglina(n = $n))
12+
SUITE["grad! tim"]["$n"] = @benchmarkable grad!(timed_nlp, get_x0(timed_nlp), $g) setup =
13+
(timed_nlp = TimerNLPModel(OptimizationProblems.ADNLPProblems.arglina(n = $n)))
14+
end
15+
for n in [100, 1000]
16+
Hv = zeros(n)
17+
SUITE["hprod! ref"]["$n"] = @benchmarkable hprod!(nlp, get_x0(nlp), get_x0(nlp), $Hv) setup =
18+
(nlp = OptimizationProblems.ADNLPProblems.arglina(n = $n))
19+
SUITE["hprod! tim"]["$n"] =
20+
@benchmarkable hprod!(timed_nlp, get_x0(timed_nlp), get_x0(timed_nlp), $Hv) setup =
21+
(timed_nlp = TimerNLPModel(OptimizationProblems.ADNLPProblems.arglina(n = $n)))
22+
end

0 commit comments

Comments
 (0)