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

Scale use case: data structure benchmark #9

Open
BrianHicks opened this issue May 11, 2018 · 0 comments
Open

Scale use case: data structure benchmark #9

BrianHicks opened this issue May 11, 2018 · 0 comments

Comments

@BrianHicks
Copy link
Collaborator

Issue by mpizenberg
Saturday Jan 06, 2018 at 08:44 GMT
Originally opened as BrianHicks/elm-benchmark#45


Hi and first of all, thanks for this package!

Context

As suggested in scale documentation and in this discourse post here is my use case for scale. I'm currently working on making JavaScript TypedArray API available in elm. My reasons are two-fold:

  1. Grow the cover of Web API in elm. Typed arrays are use for ArrayBuffers, Blobs, Files, network exchange, canvas data etc. So having them in elm is important in my opinion.
  2. They are the only fixed-size, typed structures in JS. Due to this, I'm convinced they can be used as a solid ground for fixed size efficient mathematical (Linear Algebra) library.

The code is on github: mpizenberg/elm-js-typed-array.
To make this happen, I'm benchmarking all key functions of the package (initialize, map, foldl, append, ...). Benchmarks are in the benchmarks/ directory.

Benchmark Structure

The goal of the benchmarks are to make sure that typed arrays are fast for all potential use cases, ranging from small array manipulation, to big image-like (~10^6 pixels) matrices. Therefore, I'm comparing each key function at different scales (set in Constants.sizeScales) with three data structures, List, Array and JsTypedArray (4 actually since testing both JsTypedArray Uint8 and JsTypedArray Float64).

Therefore, every benchmark file looks like the following:

module Append exposing (..)

-- imports

main : BenchmarkProgram
main =
    program <|
        describe "Append" <|
            [ lists
            , hamtArrays
            , uint8Arrays
            , float64Arrays
            ]

lists : Benchmark
lists =
    -- scale benchmark
    Constants.sizeScales
        |> List.map (\size -> ( size, List.repeat size 0 ))
        |> List.map (\( size, list ) -> ( toString size, \_ -> List.append list list ))
        |> scale "List"

hamtArrays : Benchmark
-- scale benchmark

uint8Arrays : Benchmark
-- scale benchmark

float64Arrays : Benchmark
-- scale benchmark

Results / Wished Features

At the end of the day, what I'd like to visualize is a plot comparing the different data structures at different scales. With the hypothesis that the benchmark went well and I can rely on the timing measures, I'd do a plot similar to the one below. Using logarithmic scale to make it more understandable. Plot source on this google document. With this plot, you immediately see for example that at large scale, the appending operation with JsTypedArray Uint8 is one order of magnitude faster than with other data structures.

benchmark-append-chart

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant