GithubHelp home page GithubHelp logo

java-stream-benchmarks's Introduction

java-stream-benchmarks

Micro benchmarks comparing various stream and non stream implementations of a summing algorithm. The benchmark was performed with the JMH benchmark. See this blog post for more information

To run the benchmarks execute mvn clean install && java -server -jar target/benchmarks.jar

To ensure the benchmarks work correctly add the assertions flag java -server -ea -jar target/benchmarks.jar

The stream based implementation are really trivial but they demonstrate the importance of choosing the correct collection implementation. The "traditional" algorithms are more complex but in testing proved to be much faster. For example the standard stream using a LinkedList gave 168 ops/s on my machine whereas an optimised multi threaded for loop gave over 10,000 ops/s.

java-stream-benchmarks's People

Contributors

thobson avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

java-stream-benchmarks's Issues

improved stream API performance

first of all, nice article. Unfortunately there is no possibility to leave a comment, so I have to create an issue on Github ;)

The version 'parallelArrayListStream' could be improved to get comparable performance with the hand-crafted version 'sharedStateThreadPool'.

instead of:

long sum = arrayListValues.parallelStream().mapToLong(Integer::intValue).sum();

do:

long sum = Arrays.stream(arrayValues).asLongStream().parallel().sum();

I think the mapping of integer values to long is the performance killer here.
Greetings

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.