Skip to content

Commit f59645f

Browse files
committed
Setup benchmarking example
1 parent d72135e commit f59645f

File tree

5 files changed

+80
-0
lines changed

5 files changed

+80
-0
lines changed

.github/workflows/benchmark.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Run benchmarks
2+
3+
on:
4+
pull_request:
5+
6+
jobs:
7+
Benchmark:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v2
11+
- uses: julia-actions/setup-julia@latest
12+
with:
13+
version: 1
14+
# - uses: julia-actions/julia-buildpkg@latest
15+
- name: Install dependencies
16+
run: julia -e 'using Pkg; pkg"add PkgBenchmark BenchmarkCI@0.1"'
17+
- name: Run benchmarks
18+
run: julia -e 'using BenchmarkCI; BenchmarkCI.judge(retune=true)' # retune sometimes necessary to avoid counting compile-time
19+
- name: Print judgement
20+
run: julia -e 'using BenchmarkCI; BenchmarkCI.displayjudgement()'

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Files from local benchmarking
2+
benchmark/tune.json
3+
14
# Files generated by invoking Julia with --code-coverage
25
*.jl.cov
36
*.jl.*.cov

benchmark/Project.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[deps]
2+
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
3+
PkgBenchmark = "32113eaa-f34f-5b0d-bd6c-c81e245fc73d"

benchmark/benchmarks.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
using BenchmarkTools
2+
3+
SUITE = BenchmarkGroup()
4+
5+
include("example_benchmark.jl")

benchmark/example_benchmark.jl

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
###############################
2+
### Example benchmark for Atlas
3+
###############################
4+
mech = get_mechanism(:atlas,
5+
timestep=0.1,
6+
gravity=-9.81,
7+
friction_coefficient=0.5,
8+
damper=25.0,
9+
spring=1.0,
10+
contact_feet=true,
11+
contact_body=true,
12+
model_type=:simple)
13+
14+
Dojo.initialize!(mech, :atlas_stance,
15+
body_position=[0.0, 0.0, 1.0],
16+
body_orientation=[0.0, 0.2, 0.1])
17+
18+
SUITE["atlas"] = @benchmarkable simulate!($mech, 2.5, opts=SolverOptions(rtol=1.0e-6, btol=1.0e-6)) samples=2
19+
20+
21+
###############################
22+
### Example benchmark for Pendulum
23+
###############################
24+
mechanism = get_mechanism(:pendulum,
25+
timestep=0.01,
26+
gravity=-9.81,
27+
damper=5.0,
28+
spring=0.0)
29+
30+
function controller!(mechanism, t)
31+
## Target state
32+
x_goal = [1.0 * π; 0.0]
33+
34+
## Current state
35+
x = get_minimal_state(mechanism)
36+
37+
## Gains
38+
K = [5.0 0.5] * 0.1
39+
40+
# Control inputs
41+
u = -K * (x - x_goal)
42+
set_input!(mechanism, u)
43+
end
44+
45+
initialize!(mechanism, :pendulum,
46+
angle=0.0 * π,
47+
angular_velocity=0.0);
48+
49+
SUITE["pendulum"] = @benchmarkable simulate!($mechanism, 2.0, $controller!) samples=2

0 commit comments

Comments
 (0)