diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml new file mode 100644 index 0000000..f5941e2 --- /dev/null +++ b/.github/workflows/benchmark.yml @@ -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 BenchmarkCI@0.1"' + - 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 }} \ No newline at end of file diff --git a/.gitignore b/.gitignore index 2cc6727..66d60b6 100644 --- a/.gitignore +++ b/.gitignore @@ -24,4 +24,12 @@ docs/site/ Manifest.toml # working repositories -dvpt/** \ No newline at end of file +dvpt/** + +# Related to BenchmarkCI +/.benchmarkci +/benchmark/*.json + +# Related to PkgBenchmark +benchmark/*.json +benchmark/judgement.md \ No newline at end of file diff --git a/benchmark/Project.toml b/benchmark/Project.toml new file mode 100644 index 0000000..33a8696 --- /dev/null +++ b/benchmark/Project.toml @@ -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" \ No newline at end of file diff --git a/benchmark/benchmarks.jl b/benchmark/benchmarks.jl new file mode 100644 index 0000000..25e1ffb --- /dev/null +++ b/benchmark/benchmarks.jl @@ -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 diff --git a/benchmark/run_benchmark.jl b/benchmark/run_benchmark.jl new file mode 100644 index 0000000..19ff3f0 --- /dev/null +++ b/benchmark/run_benchmark.jl @@ -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)