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 Julia as a language #63

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
9 changes: 9 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ jobs:

- name: Python
id: python

- name: Julia
id: julia

name: ${{ matrix.name }}
steps:
Expand Down Expand Up @@ -112,6 +115,12 @@ jobs:
src: "./benchmarks/Python"
if: matrix.id == 'python'

- name: Install Julia
uses: julia-actions/setup-julia@v1
with:
version: '1'
if: matrix.id == 'julia'

- name: Build
run: |
implementations/build-${{ matrix.id }}.sh
Expand Down
11 changes: 11 additions & 0 deletions benchmarks/Julia/benchmark.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function benchmark end
function verify_result end

function inner_benchmark_loop(bench, inner_iterations)
for _ in 1:inner_iterations
if !verify_result(bench, benchmark(bench))
return false
end
end
return true
end
96 changes: 96 additions & 0 deletions benchmarks/Julia/bounce.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# This code is derived from the SOM benchmarks, see AUTHORS.md file.
#
# Copyright (c) 2023 Valentin Churavy <[email protected]>

# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the 'Software'), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
module Bounce

include(joinpath(@__DIR__, "benchmark.jl"))
include(joinpath(@__DIR__, "som", "random.jl"))

mutable struct Ball
x::Int32
y::Int32
xVel::Int32
yVel::Int32
end

function Ball(rand)
x = next!(rand) % 500
y = next!(rand) % 500
xVel = (next!(rand) % 300) - 150
yVel = (next!(rand) % 300) - 150
return Ball(x, y, xVel, yVel)
end

function bounce!(b::Ball)
xLimit = Int32(500)
yLimit = Int32(500)
bounced = false

b.x += b.xVel
b.y += b.yVel

if b.x > xLimit
b.x = xLimit
b.xVel = 0 - abs(b.xVel)
bounced = true
end
if b.x < 0
b.x = 0
b.xVel = abs(b.xVel)
bounced = true
end
if b.y > yLimit
b.y = yLimit
b.yVel = 0 - abs(b.yVel)
bounced = true
end
if b.y < 0
b.y = 0
b.yVel = abs(b.yVel)
bounced = true
end
return bounced
end

struct Benchmark end

function benchmark(::Benchmark)
ballCount = 100
bounces = 0
rand = Random()

balls = [Ball(rand) for _ in 1:ballCount]

for _ in 1:50
for ball in balls
if bounce!(ball)
bounces += 1
end
end
end
return bounces
end

function verify_result(::Benchmark, result)
result == 1331
end

end # module
67 changes: 67 additions & 0 deletions benchmarks/Julia/harness.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/usr/bin/env julia
# Copyright (c) 2021 Valentin Churavy <[email protected]>

# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the 'Software'), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

mutable struct Run
name::String
benchmark::Module
total::Float64
num_iterations::Int
inner_iterations::Int
end

function Run(name, num_iterations, inner_iterations)
anon = Module()
path = joinpath(@__DIR__, "$(lowercase(name)).jl")
Base.include(anon, path)
benchmark = getproperty(anon, Symbol(name))
Run(name, benchmark, 0.0, num_iterations, inner_iterations)
end

function measure!(run::Run)
start_time = time()
benchmark = run.benchmark
@assert benchmark.inner_benchmark_loop(benchmark.Benchmark(), run.inner_iterations) "Benchmark failed with incorrect result"
end_time = time()

run_time = end_time - start_time
println("$(run.name): iterations=1 runtime: $(run_time)s")
run.total += run_time
end


function (run::Run)()
println(("Starting $(run.name) benchmark ..."))
for _ in 1:run.num_iterations
measure!(run)
end
println("$(run.name): iterations=$(run.num_iterations) average: $(run.total/run.num_iterations)s total: $(run.total)s")
end

if !(0 < length(ARGS) <= 3)
println("Usage: ./harness.jl <benchmark_name> [num_iterations] [inner_iterations]")
exit(1)
end

num_iterations = length(ARGS) >= 2 ? parse(Int, ARGS[2]) : 1
inner_iterations = length(ARGS) >= 3 ? parse(Int, ARGS[3]) : 1
let run = Run(ARGS[1], num_iterations, inner_iterations)
run()
end
10 changes: 10 additions & 0 deletions benchmarks/Julia/som/random.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
mutable struct Random
_seed::Int32
Random() = new(74755)
end

function next!(self::Random)
self._seed = ((self._seed * Int32(1309)) + Int32(13849)) & Int32(65535)

return self._seed
end
59 changes: 59 additions & 0 deletions benchmarks/Julia/storage.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# This code is derived from the SOM benchmarks, see AUTHORS.md file.
#
# Copyright (c) 2023 Valentin Churavy <[email protected]>

# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the 'Software'), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

module Storage

include(joinpath(@__DIR__, "benchmark.jl"))
include(joinpath(@__DIR__, "som", "random.jl"))


mutable struct Benchmark
_count::Int
Benchmark() = new(0)
end

function benchmark(self::Benchmark)
random = Random()
self._count = 0
build_tree_depth(self, 7, random)

return self._count
end

function build_tree_depth(self::Benchmark, depth, random)
self._count += 1
if depth == 1
return Any[nothing for _ in 1:(next!(random) % 10 + 1)]
end

arr = Any[nothing for _ in 1:4]
for i in eachindex(arr)
arr[i] = build_tree_depth(self, depth - 1, random)
end
return arr
end

function verify_result(::Benchmark, result)
result == 5461
end

end # module
6 changes: 6 additions & 0 deletions implementations/build-julia.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
set -e # make script fail on first error
SCRIPT_PATH=`dirname $0`
source $SCRIPT_PATH/script.inc

exit 0
12 changes: 12 additions & 0 deletions test.conf
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ benchmark_suites:
max_invocation_time: 60
benchmarks: *BENCHMARKS

test-julia:
gauge_adapter: RebenchLog
location: benchmarks/Julia
command: "harness.jl %(benchmark)s 1 "
max_invocation_time: 60
benchmarks: *BENCHMARKS

# VMs have a name and are specified by a path and the binary to be executed
executors:
Java8U66:
Expand Down Expand Up @@ -158,6 +165,8 @@ executors:
executable: lua5.2
Python:
executable: python
Julia:
executable: julia

experiments:
test-som:
Expand Down Expand Up @@ -200,3 +209,6 @@ experiments:
test-python:
suites: [test-python]
executions: [Python]
test-julia:
suites: [test-julia]
executions: [Julia]