Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add benchmarks, part 1 #304

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: Benchmark
on:
- pull_request
jobs:
benchmark:
name: Benchmark
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@v1
with:
version: '1.5'
- run: git fetch origin '+refs/heads/master:refs/remotes/origin/master'
- run: git branch master origin/master
- run: |
julia --project=benchmark -e '
using Pkg
Pkg.develop(PackageSpec(path=pwd()))
Pkg.instantiate()'
- run: julia --project=benchmark benchmark/runbenchmarks.jl
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ deps/usr
deps.jl
*.log
./Manifest.toml
benchmark/*.json
5 changes: 5 additions & 0 deletions benchmark/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[deps]
ArgParse = "c7e460c6-2fb9-53a9-8c5b-16f535851c63"
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
NNlib = "872c559c-99b0-510c-b3b7-b6c96a88d5cd"
PkgBenchmark = "32113eaa-f34f-5b0d-bd6c-c81e245fc73d"
12 changes: 12 additions & 0 deletions benchmark/benchmarks.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using BenchmarkTools
using NNlib

const SUITE = BenchmarkGroup()

SUITE["activations"] = BenchmarkGroup()

x = rand(64, 64)

for f in NNlib.ACTIVATIONS
SUITE["activations"][string(f)] = @benchmarkable $f.($x)
end
81 changes: 81 additions & 0 deletions benchmark/runbenchmarks.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Copied from
# https://github.com/kul-forbes/ProximalOperators.jl/tree/master/benchmark
using ArgParse
using PkgBenchmark
using Markdown

function displayresult(result)
md = sprint(export_markdown, result)
md = replace(md, ":x:" => "❌")
md = replace(md, ":white_check_mark:" => "✅")
display(Markdown.parse(md))
end

function printnewsection(name)
println()
println()
println()
printstyled("▃" ^ displaysize(stdout)[2]; color=:blue)
println()
printstyled(name; bold=true)
println()
println()
end

function parse_commandline()
s = ArgParseSettings()

@add_arg_table! s begin
"--target"
help = "the branch/commit/tag to use as target"
default = "HEAD"
"--baseline"
help = "the branch/commit/tag to use as baseline"
default = "master"
"--retune"
help = "force re-tuning (ignore existing tuning data)"
action = :store_true
end

return parse_args(s)
end

function main()
parsed_args = parse_commandline()

mkconfig(; kwargs...) =
BenchmarkConfig(
env = Dict(
"JULIA_NUM_THREADS" => "1",
);
kwargs...
)

target = parsed_args["target"]
group_target = benchmarkpkg(
dirname(@__DIR__),
mkconfig(id = target),
resultfile = joinpath(@__DIR__, "result-$(target).json"),
retune = parsed_args["retune"],
)

baseline = parsed_args["baseline"]
group_baseline = benchmarkpkg(
dirname(@__DIR__),
mkconfig(id = baseline),
resultfile = joinpath(@__DIR__, "result-$(baseline).json"),
)

printnewsection("Target result")
displayresult(group_target)

printnewsection("Baseline result")
displayresult(group_baseline)

judgement = judge(group_target, group_baseline)

printnewsection("Judgement result")
displayresult(judgement)
end

main()