Skip to content

Commit

Permalink
Added Benchmark to CI via github workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
andyferris committed Mar 11, 2020
1 parent a5d0494 commit 20d6344
Show file tree
Hide file tree
Showing 5 changed files with 236 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/TagBot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: TagBot
on:
schedule:
- cron: 0 * * * *
jobs:
TagBot:
runs-on: ubuntu-latest
steps:
- uses: JuliaRegistries/TagBot@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
19 changes: 19 additions & 0 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
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.3
- 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: Print judgement
run: julia -e 'using BenchmarkCI; BenchmarkCI.displayjudgement()'
4 changes: 4 additions & 0 deletions benchmark/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[deps]
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
PkgBenchmark = "32113eaa-f34f-5b0d-bd6c-c81e245fc73d"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
190 changes: 190 additions & 0 deletions benchmark/bench_indices.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
module BenchHashIndices

using BenchmarkTools
using Dictionaries

const suite = BenchmarkGroup()

#sizes = [(8 .^ (0:8))...]
sizes = [10, 10_000]

function build_set_by_insertion(n)
out = Set{Int}()
for i in 1:n
push!(out, i)
end
return out
end

function build_hashindices_by_insertion(n)
out = HashIndices{Int}()
for i in 1:n
insert!(out, i)
end
return out
end

function empty_by_deletion(set::Set, n)
for i in 1:n
delete!(set, i)
end
return set
end

function empty_by_deletion(indices::HashIndices, n)
for i in 1:n
delete!(indices, i)
end
return indices
end

function foreachsum(set)
count = Ref(0)
foreach(x -> count[] += 1, set)
return count[]
end


for n in sizes
r = 1:n
y = n ÷ 2
pred1(x) = x != y
pred2(x) = x == y
vec = collect(r)
set = Set(r)
indices = Indices(collect(r))
hash_indices = HashIndices(r)

s = suite["constructor ($n)"] = BenchmarkGroup()
s["Vector"] = @benchmarkable Vector($r)
s["Set"] = @benchmarkable Set($r)
s["Indices"] = @benchmarkable Indices($r)
s["HashIndices"] = @benchmarkable HashIndices($r)

s = suite["build by insertion ($n)"] = BenchmarkGroup()
s["Set"] = @benchmarkable build_set_by_insertion($n)
s["HashIndices"] = @benchmarkable build_hashindices_by_insertion($n)

#s = suite["empty by deletion ($n)"] = BenchmarkGroup()
#s["Set"] = @benchmarkable empty_by_deletion($(Set(r)), $n)
#s["HashIndices"] = @benchmarkable empty_by_deletion($(HashIndices(r)), $n)

s = suite["in ($n)"] = BenchmarkGroup()
s["Vector"] = @benchmarkable in($y, $vec)
s["Set"] = @benchmarkable in($y, $set)
s["Indices"] = @benchmarkable in($y, $indices)
s["HashIndices"] = @benchmarkable in($y, $hash_indices)

s = suite["count ($n)"] = BenchmarkGroup()
s["Vector"] = @benchmarkable count(iseven, $vec)
s["Set"] = @benchmarkable count(iseven, $set)
s["Indices"] = @benchmarkable count(iseven, $indices)
s["HashIndices"] = @benchmarkable count(iseven, $hash_indices)

s = suite["sum ($n)"] = BenchmarkGroup()
s["Vector"] = @benchmarkable sum($vec)
s["Set"] = @benchmarkable sum($set)
s["Indices"] = @benchmarkable sum($indices)
s["HashIndices"] = @benchmarkable sum($hash_indices)

s = suite["foreach ($n)"] = BenchmarkGroup()
s["Vector"] = @benchmarkable foreachsum($vec)
s["Set"] = @benchmarkable foreachsum($set)
s["Indices"] = @benchmarkable foreachsum($indices)
s["HashIndices"] = @benchmarkable foreachsum($hash_indices)

s = suite["filter-map-reduce via generator ($n)"] = BenchmarkGroup()
s["Vector"] = @benchmarkable sum($(2x for x in vec if isodd(x)))
s["Set"] = @benchmarkable sum($(2x for x in set if isodd(x)))
s["Indices"] = @benchmarkable sum($(2x for x in indices if isodd(x)))
s["HashIndices"] = @benchmarkable sum($(2x for x in hash_indices if isodd(x)))

s = suite["filter (most) ($n)"] = BenchmarkGroup()
s["Vector"] = @benchmarkable filter($pred1, $vec)
s["Set"] = @benchmarkable filter($pred1, $set)
s["Indices"] = @benchmarkable filter($pred1, $indices)
s["HashIndices"] = @benchmarkable filter($pred1, $hash_indices)

s = suite["filter (half) ($n)"] = BenchmarkGroup()
s["Vector"] = @benchmarkable filter(iseven, $vec)
s["Set"] = @benchmarkable filter(iseven, $set)
s["Indices"] = @benchmarkable filter(iseven, $indices)
s["HashIndices"] = @benchmarkable filter(iseven, $hash_indices)

s = suite["filter (few) ($n)"] = BenchmarkGroup()
s["Vector"] = @benchmarkable filter($pred2, $vec)
s["Set"] = @benchmarkable filter($pred2, $set)
s["Indices"] = @benchmarkable filter($pred2, $indices)
s["HashIndices"] = @benchmarkable filter($pred2, $hash_indices)

# s = suite["filter! (most) ($n)"] = BenchmarkGroup()
# s["Vector"] = @benchmarkable filter($pred1, $(collect(r)))
# s["Set"] = @benchmarkable filter($pred1, $(Set(r)))
# #s["Indices"] = @benchmarkable filter($pred1, $(Indices(collect(r))))
# s["HashIndices"] = @benchmarkable filter($pred1, $(HashIndices(r)))

# s = suite["filter! (half) ($n)"] = BenchmarkGroup()
# s["Vector"] = @benchmarkable filter(iseven, $(collect(r)))
# s["Set"] = @benchmarkable filter(iseven, $(Set(r)))
# #s["Indices"] = @benchmarkable filter(iseven, $(Indices(collect(r))))
# s["HashIndices"] = @benchmarkable filter(iseven, $(HashIndices(r)))

# s = suite["filter! (few) ($n)"] = BenchmarkGroup()
# s["Vector"] = @benchmarkable filter!($pred2, $(collect(r)))
# s["Set"] = @benchmarkable filter!($pred2, $(Set(r)))
# #s["Indices"] = @benchmarkable filter!($pred2, $(Indices(collect(r))))
# s["HashIndices"] = @benchmarkable filter!($pred2, $(HashIndices(r)))

even_set = Set(2:2:n)
odd_set = Set(1:2:n)
even_hash_indices = HashIndices(2:2:n)
odd_hash_indices = HashIndices(1:2:n)

s = suite["union ($n)"] = BenchmarkGroup()
s["Set"] = @benchmarkable union($even_set, $odd_set)
s["HashIndices"] = @benchmarkable union($even_hash_indices, $odd_hash_indices)

s = suite["intersect (empty) ($n)"] = BenchmarkGroup()
s["Set"] = @benchmarkable intersect($even_set, $odd_set)
s["HashIndices"] = @benchmarkable intersect($even_hash_indices, $odd_hash_indices)

s = suite["intersect (half) ($n)"] = BenchmarkGroup()
s["Set"] = @benchmarkable intersect($even_set, $set)
s["HashIndices"] = @benchmarkable intersect($even_hash_indices, $hash_indices)

s = suite["intersect (whole) ($n)"] = BenchmarkGroup()
s["Set"] = @benchmarkable intersect($set, $set)
s["HashIndices"] = @benchmarkable intersect($hash_indices, $hash_indices)

s = suite["setdiff (whole) ($n)"] = BenchmarkGroup()
s["Set"] = @benchmarkable setdiff($even_set, $odd_set)
s["HashIndices"] = @benchmarkable setdiff($even_hash_indices, $odd_hash_indices)

s = suite["setdiff (half) ($n)"] = BenchmarkGroup()
s["Set"] = @benchmarkable setdiff($even_set, $set)
s["HashIndices"] = @benchmarkable setdiff($even_hash_indices, $hash_indices)

s = suite["setdiff (empty) ($n)"] = BenchmarkGroup()
s["Set"] = @benchmarkable setdiff($set, $set)
s["HashIndices"] = @benchmarkable setdiff($hash_indices, $hash_indices)

s = suite["symdiff (whole) ($n)"] = BenchmarkGroup()
s["Set"] = @benchmarkable symdiff($even_set, $odd_set)
s["HashIndices"] = @benchmarkable symdiff($even_hash_indices, $odd_hash_indices)

s = suite["symdiff (left half) ($n)"] = BenchmarkGroup()
s["Set"] = @benchmarkable symdiff($set, $odd_set)
s["HashIndices"] = @benchmarkable symdiff($hash_indices, $hash_indices)

s = suite["symdiff (right half) ($n)"] = BenchmarkGroup()
s["Set"] = @benchmarkable symdiff($even_set, $set)
s["HashIndices"] = @benchmarkable symdiff($even_hash_indices, $odd_hash_indices)

s = suite["symdiff (empty) ($n)"] = BenchmarkGroup()
s["Set"] = @benchmarkable symdiff($set, $set)
s["HashIndices"] = @benchmarkable symdiff($hash_indices, $hash_indices)
end

end # module

BenchHashIndices.suite
12 changes: 12 additions & 0 deletions benchmark/benchmarks.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Each file of the form "bench_$(name).jl" in this directory is `include`d and
# its last statement is assumed to be a `BenchmarkGroup`. This group is added
# to the top-level group `SUITE` with the `$name` extracted from the file name.

using BenchmarkTools
const SUITE = BenchmarkGroup()
for file in sort(readdir(@__DIR__))
if startswith(file, "bench_") && endswith(file, ".jl")
SUITE[chop(file, head = length("bench_"), tail = length(".jl"))] =
include(file)
end
end

0 comments on commit 20d6344

Please sign in to comment.