Producing the Julia Microbenchmarks plot

In [1]:
# Load the required Julia packages
using DataFrames
using Gadfly
using CSV
using StatsBase
In [2]:
# Load benchmark data from file
benchmarks = CSV.read("benchmarks.csv"; header=["language", "benchmark", "time"])

# Capitalize and decorate language names from datafile
dict = Dict("c"=>"C", "julia"=>"Julia", "lua"=>"LuaJIT", "fortran"=>"Fortran", "java"=>"Java",
    "javascript"=>"JavaScript", "matlab"=>"Matlab", "mathematica"=>"Mathematica", 
    "python"=>"Python", "octave"=>"Octave", "r"=>"R", "rust"=>"Rust", "go"=>"Go");
benchmarks[:language] = [dict[lang] for lang in benchmarks[:language]]

# Normalize benchmark times by C times
ctime = benchmarks[benchmarks[:language].== "C", :]
benchmarks = join(benchmarks, ctime, on=:benchmark, makeunique=true)
delete!(benchmarks, :language_1)
rename!(benchmarks, :time_1 =>:ctime)
benchmarks[:normtime] = benchmarks[:time] ./ benchmarks[:ctime];

# Compute the geometric mean for each language
langs = [];
means = [];
priorities = [];
for lang in values(dict)
    data = benchmarks[benchmarks[:language].== lang, :]
    gmean = geomean(data[:normtime])
    push!(langs, lang)
    push!(means, gmean)
    if (lang == "C")
        push!(priorities, 1)
    elseif (lang == "Julia")
        push!(priorities, 2)        
    else
        push!(priorities, 3)
    end
end

# Add the geometric means back into the benchmarks dataframe
langmean = DataFrame(language=langs, geomean = means, priority = priorities)
benchmarks = join(benchmarks, langmean, on=:language)

# Put C first, Julia second, and sort the rest by geometric mean
sort!(benchmarks, [:priority, :geomean]);
sort!(langmean,   [:priority, :geomean]);
In [3]:
p = plot(benchmarks,
    x = :language,
    y = :normtime,
    color = :benchmark,
    Scale.y_log10,
    Guide.ylabel(nothing),
    Guide.xlabel(nothing),
    Coord.Cartesian(xmin=1,xmax=13.3,ymin=-0.5,ymax=4.2),
    Theme(
        guide_title_position = :left,
        colorkey_swatch_shape = :circle,
        minor_label_font = "Georgia",
        major_label_font = "Georgia"
    ),
)
draw(SVG(8inch,8inch/golden), p)
C Julia LuaJIT Rust Go Fortran Java JavaScript Matlab Mathematica Python R Octave iteration_pi_sum matrix_multiply matrix_statistics parse_integers print_to_file recursion_fibonacci recursion_quicksort userfunc_mandelbrot benchmark 100 101 102 103 104
In [4]:
draw(SVG("../images/benchmarks.svg", 9inch, 9inch/golden), p)
Out[4]:
false
In [5]:
# Show geometric means of microbenchmarks by language
langmean[:,1:2]
Out[5]:
languagegeomean
1C1.0
2Julia1.17006
3LuaJIT1.09231
4Rust1.0999
5Go1.49917
6Fortran1.67022
7Java3.46773
8JavaScript4.79602
9Matlab9.57235
10Mathematica14.6387
11Python16.9262
12R48.5796
13Octave338.704