Skip to content

Commit

Permalink
add benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
RAYNAUD Paul (raynaudp) authored and paraynaud committed Apr 11, 2023
1 parent a235446 commit 2879888
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 1 deletion.
25 changes: 25 additions & 0 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Run benchmarks

on:
pull_request:
types: [labeled, opened, synchronize, reopened]

# Only trigger the benchmark job when you add `run benchmark` label to the PR
jobs:
Benchmark:
runs-on: ubuntu-latest
if: contains(github.event.pull_request.labels.*.name, 'run benchmark')
steps:
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@latest
with:
version: 1
- uses: julia-actions/julia-buildpkg@latest
- name: Install dependencies
run: julia -e 'using Pkg; pkg"add PkgBenchmark [email protected]"'
- name: Run benchmarks
run: julia -e 'using BenchmarkCI; BenchmarkCI.judge()'
- name: Post results
run: julia -e 'using BenchmarkCI; BenchmarkCI.postjudge()'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
10 changes: 9 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,12 @@ docs/site/
Manifest.toml

# working repositories
dvpt/**
dvpt/**

# Related to BenchmarkCI
/.benchmarkci
/benchmark/*.json

# Related to PkgBenchmark
benchmark/*.json
benchmark/judgement.md
12 changes: 12 additions & 0 deletions benchmark/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[deps]
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
Krylov = "ba0b0d4f-ebba-5204-a429-3ac8c609bfb7"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
LinearOperators = "5c8ed15e-5a4c-59e4-a42b-c7e8811fb125"
PkgBenchmark = "32113eaa-f34f-5b0d-bd6c-c81e245fc73d"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"

[compat]
Krylov = "0.9.0"
LinearOperators = "2.4.0"
PkgBenchmark = "0.2"
63 changes: 63 additions & 0 deletions benchmark/benchmarks.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using BenchmarkTools
using Kylov, LinearAlgebra
using PartitionedVectors

const SUITE = BenchmarkGroup()

N = 5
n = 8
element_variables = [[1, 2, 3, 4], [3, 4, 5, 6], [5, 6, 7], [5, 6, 8], Int[]]

epv = PS.create_epv(element_variables; type = Float32, n)
pv_x = PartitionedVector(element_variables; T = Float32, n)

epm = PS.epm_from_epv(epv)
PS.update!(epm, epv, Float32(2.0) * epv; verbose = false)
lo_epm = LinearOperators.LinearOperator(epm)

solver = Krylov.CgSolver(pv_x)

pv_gradient = PartitionedVector(element_variables; T = Float32, n)
for i = 1:N
nie = pv_gradient[i].nie
pv_gradient[i] = rand(Float32, nie)
end

res = similar(pv_x)

Krylov.solve!(solver, lo_epm, -pv_gradient)
SUITE["Krylov small PartitionedVectors"] = BenchmarkGroup()
SUITE["Krylov small PartitionedVectors"] = @benchmarkable Krylov.solve!(solver, lo_epm, -pv_gradient)

SUITE["small broadcast"] = BenchmarkGroup()
SUITE["small broadcast"] = @benchmarkable res .= pv_gradient .+ 3 .* pv_gradient


N = 1500
n = 20000
nie = 15
element_variables = map((i -> sample(1:n, nie, replace = false)), 1:N)

epv = PS.create_epv(element_variables; type = Float32, n)
pv_x = PartitionedVector(element_variables; T = Float32, n)

epm = PS.epm_from_epv(epv)
PS.update!(epm, epv, Float32(2.0) * epv; verbose = false)
lo_epm = LinearOperators.LinearOperator(epm)

solver = Krylov.CgSolver(pv_x)

pv_gradient = PartitionedVector(element_variables; T = Float32, n)
for i = 1:N
nie = pv_gradient[i].nie
pv_gradient[i] = rand(Float32, nie)
end

res = similar(pv_x)

Krylov.solve!(solver, lo_epm, -pv_gradient)
SUITE["Krylov big PartitionedVectors"] = BenchmarkGroup()
SUITE["Krylov big PartitionedVectors"] = @benchmarkable Krylov.solve!(solver, lo_epm, -pv_gradient)

SUITE["big broadcast"] = BenchmarkGroup()
SUITE["big broadcast"] = @benchmarkable res .= pv_gradient .+ 3 .* pv_gradient
7 changes: 7 additions & 0 deletions benchmark/run_benchmark.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using PkgBenchmark

commit = benchmarkpkg("Partitionedvectors") #dernier commit sur la branche sur laquelle on se trouve
master = benchmarkpkg("Partitionedvectors", "master") # branche master
judgement = judge(commit, master)

export_markdown("benchmark/judgement.md", judgement)

0 comments on commit 2879888

Please sign in to comment.