Skip to content

Commit

Permalink
Merge pull request #59 from biaslab/bench
Browse files Browse the repository at this point in the history
Add simple benchmark suite
  • Loading branch information
wouterwln authored Mar 26, 2024
2 parents 53526b6 + 2ae0abe commit 33d9d58
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
/docs/Manifest.toml

.DS_Store
benchmark*.md
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ doc_init:
julia --project=docs -e 'ENV["PYTHON"]=""; using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate();'

docs: doc_init ## Generate documentation
julia --project=docs/ docs/make.jl
julia --project=docs/ docs/make.jl

bench: ## Run benchmark, use `make bench branch=...` to test against a specific branch
julia --startup-file=no --project=scripts/ scripts/bench.jl $(branch)
26 changes: 26 additions & 0 deletions benchmark/benchmarks.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using BenchmarkTools

const SUITE = BenchmarkGroup()

include("mockenv.jl")

function discrete_benchmarks()
SUITE = BenchmarkGroup(["Discrete Environment"])
env = RxEnvironment(MockEnvironment; is_discrete=true)
agent = add!(env, MockEntity())
SUITE["send to agent"] = @benchmarkable send!($agent, $env, 10.0)
SUITE["send to environment"] = @benchmarkable send!($env, $agent, 10.0)
return SUITE
end

function continuous_benchmarks()
SUITE = BenchmarkGroup(["Continuous Environment"])
env = RxEnvironment(MockEnvironment; is_discrete=false)
agent = add!(env, MockEntity())
SUITE["send to agent"] = @benchmarkable send!($agent, $env, 10.0)
SUITE["send to environment"] = @benchmarkable send!($env, $agent, 10.0)
return SUITE
end

SUITE["Discrete Environment"] = discrete_benchmarks()
SUITE["Continuous Environment"] = continuous_benchmarks()
30 changes: 30 additions & 0 deletions benchmark/mockenv.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using RxEnvironments

struct MockEntity end

struct MockEnvironment end

RxEnvironments.update!(subject::MockEnvironment, elapsed_time) = nothing
RxEnvironments.what_to_send(
recipient::MockEntity,
emitter::MockEnvironment,
observation::Float64,
) = 1.0

RxEnvironments.what_to_send(
recipient::MockEnvironment,
emitter::MockEntity,
observation::Float64,
) = 1.0

RxEnvironments.emits(
subject::MockEntity,
listener::MockEnvironment,
action::Float64,
) = false

RxEnvironments.emits(
subject::MockEnvironment,
listener::MockEntity,
action::Float64,
) = true
1 change: 1 addition & 0 deletions benchmark/tune.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"Julia":"1.10.2","BenchmarkTools":"1.5.0"},[["BenchmarkGroup",{"data":{"Discrete Environment":["BenchmarkGroup",{"data":{"send to environment":["Parameters",{"gctrial":true,"time_tolerance":0.05,"evals_set":false,"samples":10000,"evals":1,"gcsample":false,"seconds":5.0,"overhead":0.0,"memory_tolerance":0.01}],"send to agent":["Parameters",{"gctrial":true,"time_tolerance":0.05,"evals_set":false,"samples":10000,"evals":5,"gcsample":false,"seconds":5.0,"overhead":0.0,"memory_tolerance":0.01}]},"tags":["Discrete Environment"]}],"Continuous Environment":["BenchmarkGroup",{"data":{"send to environment":["Parameters",{"gctrial":true,"time_tolerance":0.05,"evals_set":false,"samples":10000,"evals":9,"gcsample":false,"seconds":5.0,"overhead":0.0,"memory_tolerance":0.01}],"send to agent":["Parameters",{"gctrial":true,"time_tolerance":0.05,"evals_set":false,"samples":10000,"evals":152,"gcsample":false,"seconds":5.0,"overhead":0.0,"memory_tolerance":0.01}]},"tags":["Continuous Environment"]}]},"tags":[]}]]]
16 changes: 16 additions & 0 deletions scripts/bench.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using RxEnvironments
using BenchmarkTools
using PkgBenchmark

result, name = if ARGS == []
PkgBenchmark.benchmarkpkg(RxEnvironments), "current"
else
BenchmarkTools.judge(
RxEnvironments,
ARGS[1];
judgekwargs = Dict(:time_tolerance => 0.1, :memory_tolerance => 0.05),
),
ARGS[1]
end

export_markdown("benchmark_vs_$(name)_result.md", result)

0 comments on commit 33d9d58

Please sign in to comment.