# A convenient script to plot benchmarks and make comparisons

**URL:** <https://discourse.julialang.org/t/a-convenient-script-to-plot-benchmarks-and-make-comparisons/20004>\
**Category:** General Usage\
**Tags:** plotting\
**Created:** [January 23, 2019, 8:38pm UTC](https://discourse.julialang.org/t/a-convenient-script-to-plot-benchmarks-and-make-comparisons/20004 "2019-01-23T20:38:49Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![thautwarm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thautwarm/32/37760_2.png) [@thautwarm](https://discourse.julialang.org/u/thautwarm)\
**Post date:** [January 23, 2019, 8:38pm UTC](https://discourse.julialang.org/t/a-convenient-script-to-plot-benchmarks-and-make-comparisons/20004/1 "2019-01-23T20:38:49Z")

</div>

The benchmark plotting presented at the official site looks so cool, and I want to make it conveniently, so I made this:

```julia
using Benchmarkplotting
using Gadfly
using Statistics

cases = [
    :range100 => 1:100,
    :range10000 => 1:10000,
    :array100 => [(1:100)...],
    :array10000 => [(1:100)...],
    :ice1000 => (1 for _ in 1000)
]

implementations = [
    :map =>
        function (x)
            map(e -> e + 1, x)
        end,
    :list_comp =>
        function (x)
            [e + 1 for e in x]
        end,
    :handwritten_loop =>
        function(x)
            i = 0
            arr = []
            while (iter = iterate(x, i); iter !== nothing)
                e, i = iter
                push!(arr, e + 1)
            end
            arr
        end,
    :for_iter =>
        function(x)
            arr = []
            for e in x
                push!(arr, e + 1)
            end
            arr
        end
]

criterion(benchmark_result) = (time = mean(benchmark_result.times), )

df = bcompare(criterion, cases, implementations, true)
res = report(:time, df, Scale.y_log10)
@info res[2]
draw(SVG("example.svg", 9inch, 6inch), res[1])

```

[![example](https://github.com/thautwarm/Benchmarkplotting.jl/blob/master/example.svg)](https://github.com/thautwarm/Benchmarkplotting.jl/blob/master/example.svg).

Repo [here](https://github.com/thautwarm/Benchmarkplotting.jl).
