Skip to content

Commit

Permalink
Setup benchmarking example
Browse files Browse the repository at this point in the history
  • Loading branch information
janbruedigam committed Mar 10, 2022
1 parent d72135e commit f59645f
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Run benchmarks

on:
pull_request:

jobs:
Benchmark:
runs-on: ubuntu-latest
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(retune=true)' # retune sometimes necessary to avoid counting compile-time
- name: Print judgement
run: julia -e 'using BenchmarkCI; BenchmarkCI.displayjudgement()'
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Files from local benchmarking
benchmark/tune.json

# Files generated by invoking Julia with --code-coverage
*.jl.cov
*.jl.*.cov
Expand Down
3 changes: 3 additions & 0 deletions benchmark/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[deps]
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
PkgBenchmark = "32113eaa-f34f-5b0d-bd6c-c81e245fc73d"
5 changes: 5 additions & 0 deletions benchmark/benchmarks.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
using BenchmarkTools

SUITE = BenchmarkGroup()

include("example_benchmark.jl")
49 changes: 49 additions & 0 deletions benchmark/example_benchmark.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
###############################
### Example benchmark for Atlas
###############################
mech = get_mechanism(:atlas,
timestep=0.1,
gravity=-9.81,
friction_coefficient=0.5,
damper=25.0,
spring=1.0,
contact_feet=true,
contact_body=true,
model_type=:simple)

Dojo.initialize!(mech, :atlas_stance,
body_position=[0.0, 0.0, 1.0],
body_orientation=[0.0, 0.2, 0.1])

SUITE["atlas"] = @benchmarkable simulate!($mech, 2.5, opts=SolverOptions(rtol=1.0e-6, btol=1.0e-6)) samples=2


###############################
### Example benchmark for Pendulum
###############################
mechanism = get_mechanism(:pendulum,
timestep=0.01,
gravity=-9.81,
damper=5.0,
spring=0.0)

function controller!(mechanism, t)
## Target state
x_goal = [1.0 * π; 0.0]

## Current state
x = get_minimal_state(mechanism)

## Gains
K = [5.0 0.5] * 0.1

# Control inputs
u = -K * (x - x_goal)
set_input!(mechanism, u)
end

initialize!(mechanism, :pendulum,
angle=0.0 * π,
angular_velocity=0.0);

SUITE["pendulum"] = @benchmarkable simulate!($mechanism, 2.0, $controller!) samples=2

0 comments on commit f59645f

Please sign in to comment.