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

Benchmark interpret vs compiled code evaluation #14

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ docs/site/
# It records a fixed state of all packages used by the project. As such, it should not be
# committed for packages, but should be committed for applications that require a static
# environment.
Manifest.toml
**/Manifest.toml
1 change: 1 addition & 0 deletions benchmark/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
output/
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"
HerbInterpret = "5bbddadd-02c5-4713-84b8-97364418cca7"
Metatheory = "e9d8d322-4543-424a-9be4-0cc815abe26c"
86 changes: 86 additions & 0 deletions benchmark/benchmarks.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
using Pkg
Pkg.activate(@__DIR__) # activate the benchmark environment
Pkg.instantiate()

using BenchmarkTools
using HerbInterpret
@warn "About to load Metatheory. Currently, the 3.0 development branch claims to be much faster. Consider installing it."
using Metatheory

const SUITE = BenchmarkGroup()

SUITE["interpret"] = BenchmarkGroup()

function example_function(input1)
if input1 % 5 == 0 && input1 % 3 == 0
return "FizzBuzz"
elseif input1 % 3 == 0
return "Fizz"
elseif input1 % 5 == 0
return "Buzz"
else
return string(input1)
end
end

tab = Dict{Symbol, Any}(
:% => rem,
:(==) => ==,
:string => string,
:Int => Int64,
:String => String,
:input1 => 15,
:example_function => example_function
)

Mem = Dict{Symbol,Union{Bool,Int}}
read_mem = @theory v σ begin
(v::Symbol, σ::Mem) => σ[v]
end

σ₁ = Mem(:x => 2)
program = :(x, $σ₁)

benchmark_outputs = joinpath(@__DIR__, "output")

if !isdir(benchmark_outputs) mkdir(benchmark_outputs) end

@info "Benchmarking Compiled Version"
SUITE["interpret"] = @benchmarkable example_function(15)
tune!(SUITE)
results = run(SUITE; verbose=true)
BenchmarkTools.save(joinpath(benchmark_outputs, "bench-compiled.json"), results)

println("Sleeping for 5s to relax...")
sleep(5)

@info "Benchmarking with interpreter from `HerbInterpret`"
SUITE["interpret"] = @benchmarkable interpret(tab, :(example_function(input1)))
tune!(SUITE)
results = run(SUITE; verbose=true)
BenchmarkTools.save(joinpath(benchmark_outputs, "bench-interpret.json"), results)

println("Sleeping for 5s to relax...")
sleep(5)

@info "Benchmarking With Metatheory"
SUITE["interpret"] = @benchmarkable rewrite(program, read_mem)
tune!(SUITE)
results = run(SUITE; verbose=true)
BenchmarkTools.save(joinpath(benchmark_outputs, "bench-metatheory.json"), results)

results = Dict([basename(name)[7:end-5] => BenchmarkTools.load(name) for name in readdir(benchmark_outputs, join=true)])

interpret_vs_compiled = judge(
mean(results["interpret"][1]),
mean(results["compiled"][1]),
)["interpret"]

@show interpret_vs_compiled

metatheory_vs_compiled = judge(
mean(results["metatheory"][1]),
mean(results["compiled"][1]),
)["interpret"]

@show metatheory_vs_compiled
Loading