Skip to content

Commit

Permalink
add some benchmarks (#148)
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferC committed Mar 15, 2019
1 parent 608aea9 commit 9fad884
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
1 change: 1 addition & 0 deletions benchmark/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tune.json
9 changes: 9 additions & 0 deletions benchmark/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
The benchmarks are recommended to be run using PkgBenchmark.jl as:

```
using PkgBenchmark
results = benchmarkpkg("JuliaInterpreter")
```

See the [PkgBenchmark](https://juliaci.github.io/PkgBenchmark.jl/stable/index.html) documentation for what
analysis is possible on `result`.
56 changes: 56 additions & 0 deletions benchmark/benchmarks.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using JuliaInterpreter
using BenchmarkTools

const SUITE = BenchmarkGroup()

# Recursively call itself
f(i, j) = i == 0 ? j : f(i - 1, j + 1)
SUITE["recursive self 1_000"] = @benchmarkable @interpret f(1_000, 0)

# Long stack trace calling other functions
f0(i) = i
for i in 1:1_000
@eval $(Symbol("f", i))(i) = $(Symbol("f", i-1))(i)
end
SUITE["recursive other 1_000"] = @benchmarkable @interpret f1000(1)

# Tight loop
function f(X)
s = 0
for x in X
s += x
end
return s
end
const X = rand(1:10, 10_000)
SUITE["tight loop 10_000"] = @benchmarkable @interpret f(X)

# Throwing and catching an error over a large stacktrace
function g0(i)
try
g1(i)
catch e
e
end
end
for i in 1:1_000
@eval $(Symbol("g", i))(i) = $(Symbol("g", i+1))(i)
end
g1001(i) = error()
SUITE["throw long 1_000"] = @benchmarkable @interpret g0(1)

# Function with many statements
macro do_thing(expr, N)
e = Expr(:block)
for i in 1:N
push!(e.args, esc(expr))
end
return e
end

function counter()
a = 0
@do_thing(a = a + 1, 5_000)
return a
end
SUITE["long function 5_000"] = @benchmarkable @interpret counter()

0 comments on commit 9fad884

Please sign in to comment.