Code Monkey home page Code Monkey logo

scala-datastructure-benchmark's Introduction

scala-datastructure-benchmark

A simple benchmark to estimate the speed difference of using mutable and immutable Maps as counters.

Methodology

Microbenchmarks are controversial. But we want to see their results anyway, right?

We have two tests here in this project, one using Caliper, and another wihout and such tools, using some code adapted from another test I did to compare JSON parsing libraries.

We tested three different counter update methods. We used a mutable map, an immutable map generated from a foldleft straight from the input data, and a var containing an immutable map.

Further tests also show mutable map can be about 4 times faster for integer keys.

Not Caliper

At each test run we generated different sets of random strings. Each string had 6 characters from 'a' to 'e'. That means we generated at most 56 = 15,625 different elements. We tested the methods one after the other, 11 times for each different input data size of 10k, 100k, 1M and 10M strings. In the first two cases the minimum count found at the maps was 1, while in the other the values were close to 35 and 540.

The minimum, median and maximum times from the 11 runs from each method and input sizes can be found in the tables below. We can notice the mutable map did exhibit the best times in all cases, about 40% faster than the other methods. The times from the foldLeft and the var-of-immutable methods were pretty much the same. One final interesting observation is that we can notice a somewhat linear increase in the times from 10k, 100k and 1M samples, but for 10M the time was slower. We don't know what could cause this non-linearity, we tried to use iterators for everything, and the memory consumption from the last two cases should be the same. It could be because of how memory is pre-allocated in immutable maps.

Results follow:

10k samples

methodminmedmax
mutable 6 7 130
immutable-fold 9 12 36
immutable-var 9 10 77

100k samples

methodminmedmax
mutable 60 63 68
immutable-fold 95 98 111
immutable-var 96 98 113

1M

methodminmedmax
mutable 586 601 666
immutable-fold 989 992 1,109
immutable-var 990 995 1,093

10M

methodminmedmax
mutable 7,350 8,53711,279
immutable-fold11,16213,89915,893
immutable-var 11,89714,37417,421

Tests using Caliper

Caliper showed similar results, at most ~40% faster for mutable.

input sizemutablefoldvar
8k 5.58 6.34 6.18
40k 30.31 34.60 36.29
200k 141.35 189.70 186.97
1M 675.88 1004.84 1100.15
5M 5347.58 7383.24 7608.36

cool graphic

scala-datastructure-benchmark's People

Contributors

nlw0 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.